aboutsummaryrefslogtreecommitdiff
path: root/servicecmd
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-03-24 22:31:05 +0100
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-03-24 22:50:28 +0100
commit1b3b98135eefe7cf03a379be1d5ebf13369dcfa5 (patch)
treeb9dee75d538f40557bcbd72b31f7fae30c8012ac /servicecmd
parentbb9ff43ea25dd80d5fb0f26addcef4e7b06c7990 (diff)
Add license headers and comments to source
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'servicecmd')
-rw-r--r--servicecmd/disable.c17
-rw-r--r--servicecmd/enable.c17
-rw-r--r--servicecmd/help.c17
-rw-r--r--servicecmd/list.c17
-rw-r--r--servicecmd/servicecmd.c17
-rw-r--r--servicecmd/servicecmd.h50
6 files changed, 131 insertions, 4 deletions
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) \
{ \