aboutsummaryrefslogtreecommitdiff
path: root/src/telinit.opt
diff options
context:
space:
mode:
Diffstat (limited to 'src/telinit.opt')
-rw-r--r--src/telinit.opt89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/telinit.opt b/src/telinit.opt
new file mode 100644
index 0000000..f052a53
--- /dev/null
+++ b/src/telinit.opt
@@ -0,0 +1,89 @@
+/* This file is part of GNU Pies. -*- c -*-
+ Copyright (C) 2016 Sergey Poznyakoff
+
+ GNU Pies 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 3, or (at your option)
+ any later version.
+
+ GNU Pies 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 GNU Pies. If not, see <http://www.gnu.org/licenses/>. */
+
+OPTIONS_COMMAND_BEGIN("pies",
+ [<>],
+ [<send command to init process via the legacy interface>],
+ [<[RUNLEVEL]>],
+ [<gnu>],
+ [<noversion>])
+
+OPTION(timeout,t,[<SECONDS>],
+ [<set interval between sending TERM and KILL signals>])
+BEGIN
+ char *p;
+ errno = 0;
+ shutdown_timeout = strtoul (optarg, &p, 0);
+ if (*p || errno)
+ {
+ logmsg (LOG_ERR, _("invalid number: %s"), optarg);
+ exit (EX_USAGE);
+ }
+END
+
+OPTION(environment,e,[<VAR=[VAL]>],[<change environment>])
+BEGIN
+ size_t len = strlen (optarg);
+ if (envsize + len + 2 > sizeof(req->data))
+ {
+ logmsg (LOG_ERR, _("-e argument too long"));
+ exit (EX_USAGE);
+ }
+ memcpy (req->data + envsize, optarg, len);
+ envsize += len;
+ req->data[envsize++] = 0;
+END
+
+OPTIONS_END
+
+static void
+telinit_parser (struct sysvinit_request *req, int argc, char *argv[])
+{
+ int i;
+ char *cmds[] = { "-T", NULL };
+ size_t envsize = 0;
+
+ proginfo.subcmd = cmds;
+ GETOPT(argc, argv, i);
+ argc -= i;
+ argv += i;
+ if (envsize)
+ {
+ req->data[envsize++] = 0;
+ req->cmd = INIT_CMD_SETENV;
+ if (argc)
+ {
+ logmsg (LOG_ERR, _("too many arguments"));
+ exit (EX_USAGE);
+ }
+ }
+ else
+ {
+ if (argc != 1)
+ {
+ logmsg (LOG_ERR, _("bad number of arguments"));
+ exit (EX_USAGE);
+ }
+ if (argv[0][1] || !is_valid_runlevel (argv[0][0]))
+ {
+ logmsg (LOG_ERR, _("invalid runlevel: %s"), argv[0]);
+ exit (EX_USAGE);
+ }
+ req->cmd = INIT_CMD_RUNLVL;
+ req->runlevel = argv[0][0];
+ req->sleeptime = shutdown_timeout;
+ }
+}

Return to:

Send suggestions and report system problems to the System administrator.