diff options
author | Justus Winter <justus@gnupg.org> | 2016-07-07 23:24:37 +0200 |
---|---|---|
committer | Justus Winter <justus@gnupg.org> | 2016-08-09 00:29:01 +0200 |
commit | cf040539342d513ca9ae534efd0e21116440cc86 (patch) | |
tree | 83feda7a762e38aa2b6da4fc0bea5dd51597a7c7 /sutils | |
parent | c9cd19504f87705f73294c639c9a0bc33a27aed3 (diff) |
sutils: New utility 'bless'.
* sutils/Makefile (progs): Add 'bless'.
* sutils/bless.c: New file.
Diffstat (limited to 'sutils')
-rw-r--r-- | sutils/Makefile | 2 | ||||
-rw-r--r-- | sutils/bless.c | 96 |
2 files changed, 97 insertions, 1 deletions
diff --git a/sutils/Makefile b/sutils/Makefile index b74a5063..85343f4a 100644 --- a/sutils/Makefile +++ b/sutils/Makefile @@ -20,7 +20,7 @@ dir := sutils makemode := utilities -progs = reboot halt fsck swapon swapoff +progs = reboot halt fsck swapon swapoff bless scripts = e2os MAKEDEV losetup targets = $(special-targets) $(progs) special-targets = $(scripts) diff --git a/sutils/bless.c b/sutils/bless.c new file mode 100644 index 00000000..039320ab --- /dev/null +++ b/sutils/bless.c @@ -0,0 +1,96 @@ +/* Bless processes. + + Copyright (C) 2016 Free Software Foundation, Inc. + + This file is part of the GNU Hurd. + + The GNU Hurd is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + The GNU Hurd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with the GNU Hurd. If not, see <http://www.gnu.org/licenses/>. */ + +#include <argp.h> +#include <assert.h> +#include <error.h> +#include <hurd.h> +#include <mach.h> +#include <version.h> + +const char *argp_program_version = STANDARD_HURD_VERSION (bless); + +pid_t pid; + +static const struct argp_option options[] = +{ + {0} +}; + +static const char args_doc[] = "PID"; +static const char doc[] = "Bless the given process. Such a process is " + "considered an essential part of the operating system and is not " + "terminated when switching runlevels."; + +/* Parse our options... */ +error_t +parse_opt (int key, char *arg, struct argp_state *state) +{ + char *end; + + switch (key) + { + case ARGP_KEY_ARG: + if (state->arg_num > 0) + argp_error (state, "Too many non option arguments"); + + pid = strtol (arg, &end, 10); + if (arg == end || *end != '\0') + argp_error (state, "Malformed pid '%s'", arg); + break; + + case ARGP_KEY_NO_ARGS: + argp_usage (state); + + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +const struct argp argp = + { + options: options, + parser: parse_opt, + args_doc: args_doc, + doc: doc, + }; + +int +main (int argc, char **argv) +{ + error_t err; + process_t proc; + + /* Parse our arguments. */ + argp_parse (&argp, argc, argv, 0, 0, 0); + + err = proc_pid2proc (getproc (), pid, &proc); + if (err) + error (1, err, "Could not get process for pid %d", pid); + + err = proc_mark_important (proc); + if (err) + error (1, err, "Could not mark process as important"); + + err = mach_port_deallocate (mach_task_self (), proc); + assert_perror (err); + + return EXIT_SUCCESS; +} |