Rudiments
process.h
1// Copyright (c) 1999-2018 David Muse
2// See the COPYING file for more information.
3
4#ifndef RUDIMENTS_PROCESS_H
5#define RUDIMENTS_PROCESS_H
6
7#include <rudiments/private/processincludes.h>
8
9enum childstatechange {
10 EXIT_CHILDSTATECHANGE=0,
11 TERMINATED_CHILDSTATECHANGE,
12 STOPPED_CHILDSTATECHANGE,
13 CONTINUED_CHILDSTATECHANGE
14};
15
19class RUDIMENTS_DLLSPEC process {
20 public:
21
25 static int64_t checkForPidFile(const char *filename);
26
34 static bool createPidFile(const char *filename,
35 mode_t permissions);
36
38 static pid_t getProcessId();
39
42 static pid_t getParentProcessId();
43
46 static pid_t getProcessGroupId();
47
50 static pid_t getProcessGroupId(pid_t pid);
51
54 static bool setProcessGroupId();
55
57 static bool setProcessGroupId(pid_t pgid);
58
60 static bool setProcessGroupId(pid_t pid, pid_t pgid);
61
63 static pid_t getSessionId();
64
66 static pid_t getSessionId(pid_t pid);
67
72 static pid_t createNewSession();
73
75 static uid_t getUserId();
76
78 static uid_t getEffectiveUserId();
79
85 static bool setUserId(uid_t uid);
86
92 static bool setUser(const char *username);
93
98 static bool setEffectiveUserId(uid_t uid);
99
105 static bool setEffectiveUser(const char *username);
106
115 uid_t euid);
116
118 static gid_t getGroupId();
119
121 static gid_t getEffectiveGroupId();
122
128 static bool setGroupId(gid_t gid);
129
135 static bool setGroup(const char *groupname);
136
141 static bool setEffectiveGroupId(gid_t gid);
142
148 static bool setEffectiveGroup(const char *groupname);
149
158 gid_t egid);
159
162 static mode_t setFileCreationMask(mode_t mask);
163
171 static pid_t fork();
172
175 static bool supportsFork();
176
185 static bool exec(const char *command,
186 const char * const *args);
187
198 static pid_t spawn(const char *command,
199 const char * const *args,
200 bool detached);
201
207 static bool detach();
208
211 static void exit(int32_t status);
212
217
220 static bool sendSignal(pid_t processid, int32_t signum);
221
225
228
238 static void exitOnShutDown();
239
244 static void exitOnCrash();
245
249
261
267
279 static bool registerExitHandler(void (*handler)(void));
280
294 void (*shutdownhandler)(int32_t));
295
303 static void setCrashHandler(void (*crashhandler)(int32_t));
304
320 static void setShutDownFlag(bool shutdownflag);
321
337 static bool getShutDownFlag();
338
354
370
380
391
404 static void setWaitForChildren(bool wait);
405
409 static bool wait(pid_t pid);
410
415 static bool wait(pid_t pid, int32_t *exitstatus);
416
460 static pid_t getChildStateChange(pid_t pid,
461 bool wait,
462 bool ignorestop,
463 bool ignorecontinue,
464 childstatechange *newstate,
467 bool *coredump);
468
472
479 static void setRetryFailedFork(bool retry);
480
483 static bool getRetryFailedFork();
484
492
499 static void writeBacktrace(output *out);
500
510 static void writeBacktrace(const char *filename);
511
521 static void writeBacktrace(const char *filename,
522 mode_t perms,
524
525 #include <rudiments/private/process.h>
526};
527
528#endif
Definition avltree.h:11
Definition output.h:11
Definition permissions.h:28
Definition process.h:19
static bool setEffectiveUser(const char *username)
static int32_t getShutDownSignal()
static bool registerExitHandler(void(*handler)(void))
static pid_t getProcessGroupId(pid_t pid)
static pid_t createNewSession()
static bool exec(const char *command, const char *const *args)
static bool setEffectiveUserId(uid_t uid)
static void exitImmediately(int32_t status)
static pid_t getSessionId()
static bool setUserId(uid_t uid)
static void writeBacktrace(output *out)
static bool setRealAndEffectiveGroupId(gid_t gid, gid_t egid)
static bool setEffectiveGroup(const char *groupname)
static bool setUser(const char *username)
static void setShutDownSignal(int32_t signum)
static gid_t getGroupId()
static signalhandler * getShutDownSignalHandler()
static gid_t getEffectiveGroupId()
static pid_t getSessionId(pid_t pid)
static pid_t fork()
static void exitOnCrash()
static void setRetryFailedFork(bool retry)
static bool setGroupId(gid_t gid)
static bool setProcessGroupId(pid_t pid, pid_t pgid)
static pid_t getChildStateChange(pid_t pid, bool wait, bool ignorestop, bool ignorecontinue, childstatechange *newstate, int32_t *exitstatus, int32_t *signum, bool *coredump)
static void setShutDownHandler(void(*shutdownhandler)(int32_t))
static void setWaitForChildren(bool wait)
static void writeBacktrace(const char *filename, mode_t perms, uint32_t maxframes)
static signalhandler * getCrashSignalHandler()
static bool setEffectiveGroupId(gid_t gid)
static bool supportsFork()
static bool wait(pid_t pid)
static bool setGroup(const char *groupname)
static void writeBacktrace(const char *filename)
static void exit(int32_t status)
static pid_t getParentProcessId()
static void setShutDownFlagOnCrash()
static void writeBacktrace(output *out, uint32_t maxframes)
static bool setProcessGroupId(pid_t pgid)
static uid_t getUserId()
static pid_t spawn(const char *command, const char *const *args, bool detached)
static void exitOnCrashOrShutDown()
static void setShutDownFlagOnShutDown()
static uid_t getEffectiveUserId()
static bool setProcessGroupId()
static bool sendSignal(pid_t processid, int32_t signum)
static int64_t checkForPidFile(const char *filename)
static bool getRetryFailedFork()
static bool setRealAndEffectiveUserId(uid_t uid, uid_t euid)
static bool detach()
static bool raiseSignal(int32_t signum)
static bool wait(pid_t pid, int32_t *exitstatus)
static pid_t getProcessGroupId()
static bool supportsGetChildStateChange()
static void exitOnShutDown()
static bool getShutDownFlag()
static bool createPidFile(const char *filename, mode_t permissions)
static void setShutDownFlagOnCrashOrShutDown()
static void setShutDownFlag(bool shutdownflag)
static pid_t getProcessId()
static mode_t setFileCreationMask(mode_t mask)
static void setCrashHandler(void(*crashhandler)(int32_t))
Definition signalclasses.h:89