50
46
* @pid: process id of process,
51
* @signal: signal to send.
53
* Send all processes in the same process group as @pid, which may not
54
* necessarily be the group leader the @signal.
47
* @force: force the death.
49
* Kill all processes in the same process group as @pid, which may not
50
* necessarily be the group leader.
52
* When @force is FALSE, the TERM signal is sent; when it is TRUE, KILL
56
55
* Returns: zero on success, negative value on raised error.
59
58
system_kill (pid_t pid,
64
64
nih_assert (pid > 0);
66
signal = (force ? SIGKILL : SIGTERM);
66
68
pgid = getpgid (pid);
68
70
if (kill (pgid > 0 ? -pgid : pid, signal) < 0)
166
* @type: filesystem type,
168
* @flags: mount flags.
170
* Mount the kernel filesystem @type at @dir with @flags, if not already mounted. This
171
* is used to ensure that the proc and sysfs filesystems are always
174
* Filesystems are always mounted with the MS_NODEV, MS_NOEXEC and MS_NOSUID
175
* mount options, which are sensible for /proc and /sys.
177
* Returns: zero on success, negative value on raised error.
180
system_mount (const char *type,
184
nih_local char *parent = NULL;
186
struct stat parent_stat;
187
struct stat dir_stat;
189
nih_assert (type != NULL);
190
nih_assert (dir != NULL);
192
/* Stat the parent directory of the mountpoint to obtain the dev_t */
193
ptr = strrchr (dir, '/');
194
nih_assert (ptr != NULL);
196
parent = NIH_MUST (nih_strndup (NULL, dir, ptr == dir ? 1 : ptr - dir));
197
if (stat (parent, &parent_stat) < 0)
198
nih_return_system_error (-1);
200
/* Also stat the mountpoint to obtain the dev_t */
201
if (stat (dir, &dir_stat) < 0)
202
nih_return_system_error (-1);
204
/* If the two dev_ts do not match, then there is already a filesystem
205
* mounted and we needn't do anything.
207
if (parent_stat.st_dev != dir_stat.st_dev)
210
/* Mount the filesystem */
211
if (mount ("none", dir, type, flags, NULL) < 0)
212
nih_return_system_error (-1);
221
* @mode: mode to create device with,
222
* @dev: device major and minor numbers.
224
* Create specified device.
226
* Note that depending on the device, if an error occurs
227
* it may not be reportable, hence no return value,
228
* but an attempt to display an error.
231
system_mknod (const char *path, mode_t mode, dev_t dev)
235
if (mknod (path, mode, dev) < 0 && errno != EEXIST)
236
nih_error ("%s: %s", _("Unable to create device"), path);
244
* @dev: device major and minor numbers (only checked for character and
247
* Perform checks on specified file.
249
* Returns: 0 if device exists and has the specified @path,
250
* @type and @dev attributes, else -1.
253
system_check_file (const char *path, mode_t type, dev_t dev)
260
ret = stat (path, &statbuf);
262
if (ret < 0 || ! ((statbuf.st_mode & S_IFMT) == type))
265
if (type == S_IFCHR || type == S_IFBLK) {
266
if (major (statbuf.st_rdev) != major (dev)
267
|| minor (statbuf.st_rdev) != minor (dev))