diff options
Diffstat (limited to 'src/service/util')
-rwxr-xr-x | src/service/util/servicedisc.sh | 23 | ||||
-rw-r--r-- | src/service/util/serviceutil.c | 85 | ||||
-rw-r--r-- | src/service/util/serviceutil.h | 23 | ||||
-rwxr-xr-x | src/service/util/serviceutil.sh | 28 |
4 files changed, 81 insertions, 78 deletions
diff --git a/src/service/util/servicedisc.sh b/src/service/util/servicedisc.sh index f22243b..6f95936 100755 --- a/src/service/util/servicedisc.sh +++ b/src/service/util/servicedisc.sh @@ -2,20 +2,23 @@ # # servicedisc.sh # -# Copyright (C) 2012 Vitezslav Crhonek <vcrhonek@redhat.com> +# Copyright (C) 2012 Red Hat, Inc. All rights reserved. # -# 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 2 -# of the License, or (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, +# This library 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. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser 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 <http://www.gnu.org/licenses/>. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Authors: Vitezslav Crhonek <vcrhonek@redhat.com> # diff --git a/src/service/util/serviceutil.c b/src/service/util/serviceutil.c index 7876c97..f5e3b67 100644 --- a/src/service/util/serviceutil.c +++ b/src/service/util/serviceutil.c @@ -1,19 +1,22 @@ /* - * Copyright (C) 2012 Vitezslav Crhonek <vcrhonek@redhat.com> - * Copyright (C) 2012 Radek Novacek <rnovacek@redhat.com> + * Copyright (C) 2012 Red Hat, Inc. All rights reserved. * - * 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 2 - * of the License, or (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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 <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Vitezslav Crhonek <vcrhonek@redhat.com> + * Radek Novacek <rnovacek@redhat.com> */ @@ -30,16 +33,12 @@ #define STATUS_BUFSIZE 2000 #define MAX_SLIST_CNT 1000 -/* FIXME don't use tmpnam function */ - char *suscript = "/usr/libexec/serviceutil.sh"; char *sdscript = "/usr/libexec/servicedisc.sh"; typedef struct { FILE *fp; - char name[L_tmpnam]; FILE *fp2; - char name2[L_tmpnam]; } Control; void @@ -66,28 +65,29 @@ Service_Find_All(void) Control *cc = malloc(sizeof(Control)); SList *slist; - if (cc && tmpnam(cc->name)) + if (cc) { - snprintf(cmdbuffer, STATUS_BUFSIZE, "%s > %s", sdscript, cc->name); - if (system(cmdbuffer) == 0) - cc->fp = fopen(cc->name, "r"); + cc->fp = popen(sdscript, "r"); + if (cc->fp) + { + slist = malloc(sizeof(SList)); + slist->name = malloc(MAX_SLIST_CNT * sizeof(char *)); + slist->cnt = 0; + while (fgets(svname, sizeof(svname), cc->fp) != NULL) + { + slist->name[slist->cnt] = strndup(svname, strlen(svname) - 1); + slist->cnt++; + } + pclose(cc->fp); + free(cc); + return slist; + } else { free(cc); cc=NULL; return NULL; } - slist = malloc(sizeof(SList)); - slist->name = malloc(MAX_SLIST_CNT * sizeof(char *)); - slist->cnt = 0; - while (fgets(svname, sizeof(svname), cc->fp) != NULL) - { - slist->name[slist->cnt] = strndup(svname, strlen(svname) - 1); - slist->cnt++; - } - fclose(cc->fp); - free(cc); - return slist; } else { @@ -104,20 +104,17 @@ Service_Begin_Enum(const char *service) memset(&cmdbuffer, '\0', sizeof(cmdbuffer)); - if (cc && tmpnam(cc->name) && tmpnam(cc->name2)) + if (cc) { - snprintf(cmdbuffer, STATUS_BUFSIZE, "%s status %s > %s", suscript, service, cc->name); - if (system(cmdbuffer) == 0) + snprintf(cmdbuffer, STATUS_BUFSIZE, "%s status %s", suscript, service); + cc->fp = popen(cmdbuffer, "r"); + if (cc->fp) { - cc->fp = fopen(cc->name, "r"); - snprintf(cmdbuffer, STATUS_BUFSIZE, "%s is-enabled %s > %s", suscript, service, cc->name2); - if (system(cmdbuffer) == 0) - { - cc->fp2 = fopen(cc->name2, "r"); - } - else + snprintf(cmdbuffer, STATUS_BUFSIZE, "%s is-enabled %s", suscript, service); + cc->fp2 = popen(cmdbuffer, "r"); + if (!cc->fp2) { - fclose(cc->fp); + pclose(cc->fp); free(cc); cc=NULL; } @@ -195,10 +192,8 @@ Service_End_Enum(void *handle) Control *cc = (Control *) handle; if (cc) { - fclose(cc->fp); - fclose(cc->fp2); - remove(cc->name); - remove(cc->name2); + pclose(cc->fp); + pclose(cc->fp2); free(cc); } } diff --git a/src/service/util/serviceutil.h b/src/service/util/serviceutil.h index 9fd7abe..e1318ea 100644 --- a/src/service/util/serviceutil.h +++ b/src/service/util/serviceutil.h @@ -1,18 +1,21 @@ /* - * Copyright (C) 2012 Vitezslav Crhonek <vcrhonek@redhat.com> + * Copyright (C) 2012 Red Hat, Inc. All rights reserved. * - * 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 2 - * of the License, or (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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 <http://www.gnu.org/licenses/>. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Vitezslav Crhonek <vcrhonek@redhat.com> */ diff --git a/src/service/util/serviceutil.sh b/src/service/util/serviceutil.sh index bcfcf46..5c26651 100755 --- a/src/service/util/serviceutil.sh +++ b/src/service/util/serviceutil.sh @@ -2,22 +2,24 @@ # # serviceutil.sh # -# Copyright (C) 2012 Vitezslav Crhonek <vcrhonek@redhat.com> +# Copyright (C) 2012 Red Hat, Inc. All rights reserved. # -# 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 2 -# of the License, or (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, +# This library 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. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser 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 <http://www.gnu.org/licenses/>. +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Authors: Vitezslav Crhonek <vcrhonek@redhat.com> # - # path to systemd service directory SYSTEMD_SDIR=/lib/systemd/system @@ -30,10 +32,10 @@ if [ -f $SYSTEMD_SDIR/$SUNIT_NAME ]; then case "$1" in start|stop|reload|restart|try-restart|condrestart|reload-or-restart|reload-or-try-restart|enable|disable|is-enabled) - systemctl $1 $SUNIT_NAME + systemctl -- $1 $SUNIT_NAME ;; status) - output=`systemctl status $SUNIT_NAME` + output=`systemctl -- status $SUNIT_NAME` if echo "$output" | grep Active: | grep inactive > /dev/null 2>&1; then echo "stopped" elif echo "$output" | grep Active: | grep failed > /dev/null 2>&1; then |