message.c (2010B)
1 #include "message.h" 2 3 #include "config.h" 4 5 #include <libgen.h> 6 #include <stdio.h> 7 #include <stdlib.h> 8 9 static const char* prog_usage[] = { 10 [PROG_FINIT] = "init <0|6>", 11 [PROG_FSVC] = "fsvc <command> [-v --verbose] [-V --version] [-r --runlevel <level>] [-s --service-dir <path>]\n" 12 " fsvc start [-p --pin] <service>\n" 13 " fsvc stop [-p --pin] <service>\n" 14 " fsvc enable [-o --once] <service>\n" 15 " fsvc disable [-o --once] <service>\n" 16 " fsvc kill <service> <signal|signum>\n" 17 " fsvc status [-c --check] <service>\n" 18 " fsvc pause <service>\n" 19 " fsvc resume <service>\n" 20 " fsvc switch [-f --reset] <runlevel>", 21 [PROG_FSVS] = "fsvs [-V --version] [-v --verbose] [-f --force] <service-dir> <runlevel>", 22 [PROG_HALT] = "halt [-n] [-f] [-d] [-w] [-B]", 23 [PROG_POWEROFF] = "poweroff [-n] [-f] [-d] [-w] [-B]", 24 [PROG_REBOOT] = "reboot [-n] [-f] [-d] [-w] [-B]", 25 [PROG_SEEDRNG] = "seedrng", 26 [PROG_SIGREMAP] = "sigremap [-s --single] [-v --verbose] [-V --version] <old-signal=new-signal...> <command> [args...]", 27 [PROG_VLOGGER] = "vlogger [-isS] [-f file] [-p pri] [-t tag] [message ...]", 28 [PROG_ZZZ] = "zzz [-n --noop] [-S --freeze] [-z --suspend] [-Z --hibernate] [-R --reboot] [-H --hybrid]" 29 }; 30 31 static const char* prog_manual[] = { 32 [PROG_FINIT] = "finit 8", 33 [PROG_FSVC] = "fsvc 8", 34 [PROG_FSVS] = "fsvs 8", 35 [PROG_HALT] = "halt 8", 36 [PROG_POWEROFF] = "poweroff 8", 37 [PROG_REBOOT] = "reboot 8", 38 [PROG_SEEDRNG] = "seedrng 8", 39 [PROG_SIGREMAP] = "sigremap 8", 40 [PROG_VLOGGER] = "vlogger 1", 41 [PROG_ZZZ] = "zzz 8" 42 }; 43 44 void print_usage_exit(enum prog prog, int status) { 45 fprintf(status ? stderr : stdout, "Usage: %s\n\nCheck manual '%s' for more information.\n", prog_usage[prog], prog_manual[prog]); 46 exit(status); 47 } 48 49 void print_version_exit(void) { 50 print(SV_VERSION); 51 exit(0); 52 }