summaryrefslogtreecommitdiff
blob: 140df1ec8fa5291ea3fa73ad55c4dc5f05a8faf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * services.c
 *
 * Functions dealing with services.
 *
 * Copyright (C) 2004-2006 Martin Schlemmer <azarah@nosferatu.za.org>
 *
 *
 *      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 version 2 of the License.
 *
 *      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, write to the Free Software Foundation, Inc.,
 *      675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Header$
 */

#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

#include "internal/rccore.h"

char *rc_service_state_names[] = {
  "coldplugged",
  "starting",
  "started",
  "inactive",
  "wasinactive",
  "stopping",
  NULL
};

bool
rc_service_test_state (const char *service, rc_service_state_t state)
{
  char *state_dir;
  char *state_link;

  if (!check_str (service))
    return FALSE;

  /*
   * NB: Should check if its actually a valid service before doing all the
   *     rest of the checks!
   */

  if (rc_file_exists (RC_SYSINIT_STATE))
    return FALSE;

  state_dir = rc_strcatpaths (rc_config_svcdir, rc_service_state_names[state]);
  if (NULL == state_dir)
    {
      DBG_MSG ("Failed to allocate buffer!\n");
      return FALSE;
    }

  state_link = rc_strcatpaths (state_dir, service);
  if (NULL == state_link)
    {
      free (state_dir);
      DBG_MSG ("Failed to allocate buffer!\n");
      return FALSE;
    }

  if (rc_file_exists (state_link))
    {
      free (state_link);
      free (state_dir);
      return TRUE;
    }

  free (state_link);
  free (state_dir);

  return FALSE;
}