/* 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 . */
OPTIONS_COMMAND_BEGIN("pies",
[<>],
[],
[<[RUNLEVEL]>],
[],
[])
OPTION(timeout,t,[],
[])
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,[],[])
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;
}
}