FreeNOS
kill.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <FreeNOS/User.h>
19 #include "stdlib.h"
20 #include "errno.h"
21 #include "signal.h"
22 
23 extern C int kill(pid_t pid, int sig)
24 {
25  switch (sig)
26  {
27  case SIGTERM:
28  case SIGKILL:
29  {
30  const API::Result result = ProcessCtl(pid, KillPID, EXIT_FAILURE);
31  if (result == API::Success)
32  {
33  return 0;
34  }
35  else
36  {
37  errno = EIO;
38  return -1;
39  }
40  }
41 
42  default:
43  break;
44  }
45 
46  // Not supported
47  errno = ENOTSUP;
48  return -1;
49 }
EXIT_FAILURE
#define EXIT_FAILURE
Unsuccessful termination.
Definition: stdlib.h:36
API::Result
Result
Enumeration of generic kernel API result codes.
Definition: API.h:68
errno
C int errno
The lvalue errno is used by many functions to return error values.
ProcessCtl
API::Result ProcessCtl(const ProcessID proc, const ProcessOperation op, const Address addr=0, const Address output=0)
Prototype for user applications.
Definition: ProcessCtl.h:93
C
#define C
Used to define external C functions.
Definition: Macros.h:134
ENOTSUP
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:226
SIGTERM
#define SIGTERM
Termination request.
Definition: signal.h:54
signal.h
EIO
#define EIO
I/O error.
Definition: errno.h:130
pid_t
ProcessID pid_t
Used for process IDs and process group IDs.
Definition: types.h:32
API::Success
@ Success
Definition: API.h:70
kill
C int kill(pid_t pid, int sig)
Send a signal to a process or a group of processes.
Definition: kill.cpp:23
stdlib.h
KillPID
@ KillPID
Definition: ProcessCtl.h:40
SIGKILL
#define SIGKILL
Killed.
Definition: signal.h:77
errno.h