commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[hurd] 17/19: sutils: New utility 'bless'.


From: Samuel Thibault
Subject: [hurd] 17/19: sutils: New utility 'bless'.
Date: Wed, 10 Aug 2016 00:05:51 +0000

This is an automated email from the git hooks/post-receive script.

sthibault pushed a commit to branch upstream
in repository hurd.

commit cf040539342d513ca9ae534efd0e21116440cc86
Author: Justus Winter <address@hidden>
Date:   Thu Jul 7 23:24:37 2016 +0200

    sutils: New utility 'bless'.
    
    * sutils/Makefile (progs): Add 'bless'.
    * sutils/bless.c: New file.
---
 sutils/Makefile |  2 +-
 sutils/bless.c  | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 1 deletion(-)

diff --git a/sutils/Makefile b/sutils/Makefile
index b74a506..85343f4 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 0000000..039320a
--- /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;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-hurd/hurd.git



reply via email to

[Prev in Thread] Current Thread [Next in Thread]