2008-01-14 05:05:22 +00:00
|
|
|
/*
|
2015-12-04 16:52:19 -06:00
|
|
|
* Copyright (c) 2007-2015 The OpenRC Authors.
|
|
|
|
* See the Authors file at the top-level directory of this distribution and
|
|
|
|
* https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
2011-02-12 19:15:29 -06:00
|
|
|
*
|
2015-12-04 16:52:19 -06:00
|
|
|
* This file is part of OpenRC. It is subject to the license terms in
|
|
|
|
* the LICENSE file found in the top-level directory of this
|
|
|
|
* distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
|
|
|
* This file may not be copied, modified, propagated, or distributed
|
|
|
|
* except according to the terms contained in the LICENSE file.
|
2007-04-17 12:44:32 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-12 19:15:29 -06:00
|
|
|
#include "version.h"
|
2011-11-19 02:43:25 -05:00
|
|
|
#include <ctype.h>
|
2011-02-12 19:15:29 -06:00
|
|
|
|
2008-01-22 11:07:39 +00:00
|
|
|
#if lint
|
2009-04-23 21:31:22 +00:00
|
|
|
# define _noreturn
|
2008-01-22 11:07:39 +00:00
|
|
|
#endif
|
2008-02-22 11:44:10 +00:00
|
|
|
#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
|
2009-04-23 21:31:22 +00:00
|
|
|
# define _noreturn __attribute__ ((__noreturn__))
|
2008-02-22 11:44:10 +00:00
|
|
|
#else
|
2009-04-23 21:31:22 +00:00
|
|
|
# define _noreturn
|
2008-01-22 11:07:39 +00:00
|
|
|
#endif
|
|
|
|
|
2013-09-01 17:36:37 -05:00
|
|
|
static void set_quiet_options(void)
|
|
|
|
{
|
|
|
|
static int qcount = 0;
|
|
|
|
|
|
|
|
qcount ++;
|
|
|
|
switch (qcount) {
|
|
|
|
case 1:
|
|
|
|
setenv ("EINFO_QUIET", "YES", 1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
setenv ("EERROR_QUIET", "YES", 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-12 19:15:29 -06:00
|
|
|
_noreturn static void
|
|
|
|
show_version(void)
|
|
|
|
{
|
2016-01-01 13:13:28 -06:00
|
|
|
char *systype = NULL;
|
2011-02-12 19:15:29 -06:00
|
|
|
|
|
|
|
printf("%s (OpenRC", applet);
|
2015-12-07 17:56:02 -06:00
|
|
|
systype = detect_container();
|
|
|
|
if (!systype)
|
|
|
|
systype = detect_vm();
|
|
|
|
if (systype)
|
2015-12-05 17:47:47 -06:00
|
|
|
printf(" [%s]", systype);
|
2011-02-12 19:15:29 -06:00
|
|
|
printf(") %s", VERSION);
|
|
|
|
#ifdef BRANDING
|
|
|
|
printf(" (%s)", BRANDING);
|
|
|
|
#endif
|
|
|
|
printf("\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2009-04-23 21:31:22 +00:00
|
|
|
_noreturn static void
|
|
|
|
usage(int exit_status)
|
2007-04-17 12:44:32 +00:00
|
|
|
{
|
2007-09-25 22:57:32 +00:00
|
|
|
const char * const has_arg[] = { "", "<arg>", "[arg]" };
|
2007-04-17 12:44:32 +00:00
|
|
|
int i;
|
2008-03-16 17:00:56 +00:00
|
|
|
int len;
|
|
|
|
char *lo;
|
|
|
|
char *p;
|
|
|
|
char *token;
|
2011-11-19 02:43:25 -05:00
|
|
|
char val[4] = "-?,";
|
2007-12-19 12:46:08 +00:00
|
|
|
|
2008-01-15 09:50:14 +00:00
|
|
|
#ifdef usagestring
|
2008-03-16 17:00:56 +00:00
|
|
|
printf(usagestring);
|
2008-01-15 09:50:14 +00:00
|
|
|
#else
|
2008-03-16 17:00:56 +00:00
|
|
|
printf("Usage: %s [options] ", applet);
|
2008-01-15 09:50:14 +00:00
|
|
|
#endif
|
2007-09-21 11:52:37 +00:00
|
|
|
#ifdef extraopts
|
2008-03-16 17:00:56 +00:00
|
|
|
printf(extraopts);
|
2007-09-21 11:52:37 +00:00
|
|
|
#endif
|
2008-03-16 17:00:56 +00:00
|
|
|
printf("\n\nOptions: [" getoptstring "]\n");
|
2007-09-25 22:57:32 +00:00
|
|
|
for (i = 0; longopts[i].name; ++i) {
|
2011-11-19 02:43:25 -05:00
|
|
|
val[1] = longopts[i].val;
|
|
|
|
len = printf(" %3s --%s %s", isprint(longopts[i].val) ? val : "",
|
|
|
|
longopts[i].name, has_arg[longopts[i].has_arg]);
|
2007-10-29 16:02:18 +00:00
|
|
|
|
2008-03-16 17:00:56 +00:00
|
|
|
lo = p = xstrdup(longopts_help[i]);
|
|
|
|
while ((token = strsep(&p, "\n"))) {
|
2011-11-19 02:39:08 -05:00
|
|
|
len = 36 - len;
|
|
|
|
if (len > 0)
|
|
|
|
printf("%*s", len, "");
|
2008-03-16 17:00:56 +00:00
|
|
|
puts(token);
|
2007-10-29 16:02:18 +00:00
|
|
|
len = 0;
|
|
|
|
}
|
2008-03-16 17:00:56 +00:00
|
|
|
free(lo);
|
2007-09-25 22:57:32 +00:00
|
|
|
}
|
2008-03-16 17:00:56 +00:00
|
|
|
exit(exit_status);
|
2007-04-17 12:44:32 +00:00
|
|
|
}
|