diff options
author | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-03-24 22:31:05 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@tele2.at> | 2018-03-24 22:50:28 +0100 |
commit | 1b3b98135eefe7cf03a379be1d5ebf13369dcfa5 (patch) | |
tree | b9dee75d538f40557bcbd72b31f7fae30c8012ac | |
parent | bb9ff43ea25dd80d5fb0f26addcef4e7b06c7990 (diff) |
Add license headers and comments to source
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
-rw-r--r-- | cmd/shutdown.c | 17 | ||||
-rw-r--r-- | initd/init.h | 96 | ||||
-rw-r--r-- | initd/main.c | 17 | ||||
-rw-r--r-- | initd/mksock.c | 17 | ||||
-rw-r--r-- | initd/runlst.c | 17 | ||||
-rw-r--r-- | initd/setup_tty.c | 17 | ||||
-rw-r--r-- | initd/shutdown.c | 17 | ||||
-rw-r--r-- | initd/status.c | 17 | ||||
-rw-r--r-- | initd/svclist.c | 17 | ||||
-rw-r--r-- | lib/include/service.h | 47 | ||||
-rw-r--r-- | lib/include/telinit.h | 20 | ||||
-rw-r--r-- | lib/include/util.h | 22 | ||||
-rw-r--r-- | lib/src/del_srv_list.c | 17 | ||||
-rw-r--r-- | lib/src/delsrv.c | 17 | ||||
-rw-r--r-- | lib/src/enum_by_name.c | 17 | ||||
-rw-r--r-- | lib/src/opensock.c | 17 | ||||
-rw-r--r-- | lib/src/rdline.c | 17 | ||||
-rw-r--r-- | lib/src/rdsrv.c | 17 | ||||
-rw-r--r-- | lib/src/splitkv.c | 17 | ||||
-rw-r--r-- | lib/src/srv_tsort.c | 17 | ||||
-rw-r--r-- | lib/src/srvscan.c | 17 | ||||
-rw-r--r-- | lib/src/strexpand.c | 17 | ||||
-rw-r--r-- | servicecmd/disable.c | 17 | ||||
-rw-r--r-- | servicecmd/enable.c | 17 | ||||
-rw-r--r-- | servicecmd/help.c | 17 | ||||
-rw-r--r-- | servicecmd/list.c | 17 | ||||
-rw-r--r-- | servicecmd/servicecmd.c | 17 | ||||
-rw-r--r-- | servicecmd/servicecmd.h | 50 |
28 files changed, 614 insertions, 12 deletions
diff --git a/cmd/shutdown.c b/cmd/shutdown.c index 16e0c8e..0d11cc5 100644 --- a/cmd/shutdown.c +++ b/cmd/shutdown.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <getopt.h> #include <stdlib.h> #include <string.h> diff --git a/initd/init.h b/initd/init.h index 0bfed6c..dee0b00 100644 --- a/initd/init.h +++ b/initd/init.h @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #ifndef INIT_H #define INIT_H @@ -14,22 +31,101 @@ enum { STATUS_WAIT, }; +/********** runlst.c **********/ + +/* + Plow through an array of strings and execute each one, i.e. do + a fork() and exec(). + + In the parent process, wait() until the child is done before + continuing through the list. + + If ctty is not NULL, open it and redirect all I/O of the child + process to that file. + + If everyhing works, the function returns EXIT_SUCCESS. If one child + does not exit with EXIT_SUCCESS, processing of the list is aborted + and the function returns the exit status of the failed process. +*/ int runlst_wait(char **exec, size_t num, const char *ctty); +/* + Does basically the same as runlst_wait, but asynchronously. + + A child process is created that calls runlst_wait exits with the + result of runlst_wait. In the parent process, the function returns + immediately with the PID of the child process. + + Alternatively, if num is 1, the child process directly exec()s the + given command. +*/ pid_t runlst(char **exec, size_t num, const char *ctty); +/********** setup_tty.c **********/ + +/* + Initial tty setup for init. Makes /dev/console our controlling tty and + reroutes all output there. Closes stdin because we presumably won't + need it anymore. + + Returns 0 on success, -1 on failure. The function takes care of + printing error messages on failure. +*/ int setup_tty(void); +/********** status.c **********/ + +/* + Print a status message. Type is either STATUS_OK, STATUS_FAIL or + STATUS_WAIT. + + A new-line is appended to the mssage, UNLESS type is STATUS_WAIT. + + If update is true, print a carriage return first to overwrite the + current line (e.g. after a STATUS_WAIT message). +*/ void print_status(const char *msg, int type, bool update); +/********** mksock.c **********/ + +/* + Create a UNIX socket that programs can use to pass messages to init. + + Returns the socked fd or -1 on failure. The function takes care of + printing error messages on failure. + + The socket has the CLOEXEC flag set. +*/ int mksock(void); +/********** shutdown.c **********/ + +/* + Kindly tell all processes to go kill themselves, then send + a SIGKILL if they don't and perform system shutdown. + + The argument is passed directly to the reboot() syscall. +*/ NORETURN void do_shutdown(int type); +/********** svclist.c **********/ + +/* + Returns true if the list of running services contains + single shot processes. +*/ bool svclist_have_singleshot(void); +/* Add a service to the list of running services */ void svclist_add(service_t *svc); +/* + Remove a service, identifierd by PID, from the list of + running services. + + Returns the service identified by the PID or NULL if there + is no such service. +*/ service_t *svclist_remove(pid_t pid); #endif /* INIT_H */ diff --git a/initd/main.c b/initd/main.c index 211188e..be9fc0d 100644 --- a/initd/main.c +++ b/initd/main.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/types.h> #include <sys/wait.h> #include <sys/socket.h> diff --git a/initd/mksock.c b/initd/mksock.c index ab26e51..6a9cab0 100644 --- a/initd/mksock.c +++ b/initd/mksock.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> diff --git a/initd/runlst.c b/initd/runlst.c index cf75126..908ec15 100644 --- a/initd/runlst.c +++ b/initd/runlst.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/wait.h> #include <signal.h> #include <unistd.h> diff --git a/initd/setup_tty.c b/initd/setup_tty.c index cec663b..807b69d 100644 --- a/initd/setup_tty.c +++ b/initd/setup_tty.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <unistd.h> #include <fcntl.h> #include <stdio.h> diff --git a/initd/shutdown.c b/initd/shutdown.c index 45af1c2..1ee68c2 100644 --- a/initd/shutdown.c +++ b/initd/shutdown.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <stdlib.h> #include <unistd.h> #include <string.h> diff --git a/initd/status.c b/initd/status.c index 280670b..67b049b 100644 --- a/initd/status.c +++ b/initd/status.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <stdio.h> #include "init.h" diff --git a/initd/svclist.c b/initd/svclist.c index 590091e..4ed897f 100644 --- a/initd/svclist.c +++ b/initd/svclist.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include "init.h" static service_t *running = NULL; /* currently supervised services */ diff --git a/lib/include/service.h b/lib/include/service.h index eb92d85..6808bdd 100644 --- a/lib/include/service.h +++ b/lib/include/service.h @@ -1,19 +1,45 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #ifndef SERVICE_H #define SERVICE_H #include <sys/types.h> enum { + /* + Start the service in the background and continue with + other services. The service will eventually terminate. + */ SVC_ONCE = 0, - SVC_WAIT, + SVC_WAIT, /* run service and wait until it finishes */ + + /* + Similar to SVC_ONCE, but restart the service when + it terminates. + */ SVC_RESPAWN, }; enum { - TGT_BOOT = 0, - TGT_SHUTDOWN, - TGT_REBOOT, - TGT_CAD, + TGT_BOOT = 0, /* run service when the system boots */ + TGT_SHUTDOWN, /* run service when at system shut down */ + TGT_REBOOT, /* run service when during system reboot */ + TGT_CAD, /* run service when CTRL+ALT+DEL is pressed */ TGT_MAX }; @@ -27,9 +53,9 @@ typedef struct service_t { size_t num_exec; /* number of command lines */ char *ctty; /* controlling tty or log file */ - char **before; + char **before; /* services that must be executed later */ size_t num_before; - char **after; + char **after; /* services that must be executed first */ size_t num_after; pid_t pid; @@ -49,6 +75,13 @@ service_t *rdsrv(int dirfd, const char *filename); void delsrv(service_t *srv); +/* + Rebuild a service list by scanning a directory and parsing all + service descriptions. + + Returns 0 on success, -1 on failure. The function takes care of + printing error messages on failure. +*/ int srvscan(const char *directory, service_list_t *list); void del_srv_list(service_list_t *list); diff --git a/lib/include/telinit.h b/lib/include/telinit.h index 72ad871..3a3dd8c 100644 --- a/lib/include/telinit.h +++ b/lib/include/telinit.h @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #ifndef TELINIT_H #define TELINIT_H @@ -11,9 +28,10 @@ enum { }; typedef struct { - int type; + int type; /* TI_* message type identifier */ } ti_msg_t; +/* Try to connect to the init socket. */ int opensock(void); #endif /* TELINIT_H */ diff --git a/lib/include/util.h b/lib/include/util.h index bed2ba7..ed5dac2 100644 --- a/lib/include/util.h +++ b/lib/include/util.h @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #ifndef UTIL_H #define UTIL_H @@ -52,6 +69,11 @@ int splitkv(char *line, char **key, char **value); */ const enum_map_t *enum_by_name(const enum_map_t *map, const char *name); +/* + Create a copy of the input string inp, but replace all occourances + of %<number> with argv[number] if the number is within the bounds + specified by argc. +*/ char *strexpand(const char *inp, size_t argc, const char *const *argv); #endif /* UTIL_H */ diff --git a/lib/src/del_srv_list.c b/lib/src/del_srv_list.c index 916fcb2..d54c40b 100644 --- a/lib/src/del_srv_list.c +++ b/lib/src/del_srv_list.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <stdlib.h> #include "service.h" diff --git a/lib/src/delsrv.c b/lib/src/delsrv.c index b660558..87b65bc 100644 --- a/lib/src/delsrv.c +++ b/lib/src/delsrv.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <stdlib.h> #include "service.h" diff --git a/lib/src/enum_by_name.c b/lib/src/enum_by_name.c index 1948eb9..95f306f 100644 --- a/lib/src/enum_by_name.c +++ b/lib/src/enum_by_name.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <string.h> #include "util.h" diff --git a/lib/src/opensock.c b/lib/src/opensock.c index 06101ef..0c2bf56 100644 --- a/lib/src/opensock.c +++ b/lib/src/opensock.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> diff --git a/lib/src/rdline.c b/lib/src/rdline.c index 591c713..1b91008 100644 --- a/lib/src/rdline.c +++ b/lib/src/rdline.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <stdlib.h> #include <unistd.h> #include <errno.h> diff --git a/lib/src/rdsrv.c b/lib/src/rdsrv.c index 52eb19c..ec60ce1 100644 --- a/lib/src/rdsrv.c +++ b/lib/src/rdsrv.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> diff --git a/lib/src/splitkv.c b/lib/src/splitkv.c index 6c6fe94..b1ef8d3 100644 --- a/lib/src/splitkv.c +++ b/lib/src/splitkv.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <ctype.h> #include "util.h" diff --git a/lib/src/srv_tsort.c b/lib/src/srv_tsort.c index e2549b1..d375c4f 100644 --- a/lib/src/srv_tsort.c +++ b/lib/src/srv_tsort.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <stdbool.h> #include <stddef.h> #include <string.h> diff --git a/lib/src/srvscan.c b/lib/src/srvscan.c index 71ad4f9..69d0b91 100644 --- a/lib/src/srvscan.c +++ b/lib/src/srvscan.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/types.h> #include <sys/stat.h> #include <stddef.h> diff --git a/lib/src/strexpand.c b/lib/src/strexpand.c index 7e552eb..58b69a0 100644 --- a/lib/src/strexpand.c +++ b/lib/src/strexpand.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <string.h> #include <stdlib.h> #include <ctype.h> diff --git a/servicecmd/disable.c b/servicecmd/disable.c index 90d8b80..1901381 100644 --- a/servicecmd/disable.c +++ b/servicecmd/disable.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> diff --git a/servicecmd/enable.c b/servicecmd/enable.c index 8e6200c..73ea01e 100644 --- a/servicecmd/enable.c +++ b/servicecmd/enable.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> diff --git a/servicecmd/help.c b/servicecmd/help.c index 6cd816e..4fa9951 100644 --- a/servicecmd/help.c +++ b/servicecmd/help.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include "servicecmd.h" extern char *__progname; diff --git a/servicecmd/list.c b/servicecmd/list.c index 2286197..aad70d6 100644 --- a/servicecmd/list.c +++ b/servicecmd/list.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include "servicecmd.h" #include "service.h" #include "config.h" diff --git a/servicecmd/servicecmd.c b/servicecmd/servicecmd.c index 278afaf..ff37740 100644 --- a/servicecmd/servicecmd.c +++ b/servicecmd/servicecmd.c @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #include <stdlib.h> #include <stdio.h> diff --git a/servicecmd/servicecmd.h b/servicecmd/servicecmd.h index ce5e58f..27204d0 100644 --- a/servicecmd/servicecmd.h +++ b/servicecmd/servicecmd.h @@ -1,3 +1,20 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * Copyright (C) 2018 - David Oberhollenzer + * + * This program 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 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ #ifndef SERVICECMD_H #define SERVICECMD_H @@ -8,21 +25,46 @@ #include "util.h" +/* + Describes a command that can be launched by passing its name as + second command line argument to the main() function (i.e. immediately + after the actual program name). + + Short and long descriptions can be provided to print out help text. + + The main() function calls into a callback in this structure to execute + the command. +*/ typedef struct command_t { struct command_t *next; - const char *cmd; - const char *usage; - const char *s_desc; - const char *l_desc; + const char *cmd; /* command name */ + const char *usage; /* list of possible arguments */ + const char *s_desc; /* short description used by help */ + const char *l_desc; /* long description used by help */ + /* + Semantics are the same as for main(). Called from main() + function with first argument (i.e. top level program name) + removed. + */ int (*run_cmd)(int argc, char **argv); } command_t; +/* Global list of available commands */ extern command_t *commands; +/* + Implemented in servicecmd.c. Prints program usage message and + terminates with the given exit status. +*/ void usage(int status) NORETURN; +/* + To implement a new command, add a global, static instance of a + command_t (or derived) structure to a C file and pass it to this + macro to have it automatically registered on program startup. +*/ #define REGISTER_COMMAND(cmd) \ static void __attribute__((constructor)) register_##cmd(void) \ { \ |