fix build warning
[platform/core/system/libsyscommon.git] / src / libsystemd / systemd-state.c
1 /*
2  * libsyscommon
3  *
4  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <libgdbus/dbus-systemd.h>
22
23 #include "shared/log.h"
24
25 #define SYSTEMD_DBUS_METHOD_SYSTEM_STATE        "SystemState"
26 #define SYSTEMD_STATE_RUNNING                           "running"
27 #define SYSTEMD_STATE_DEGRADED                          "degraded"
28
29 int check_system_boot_finished(void)
30 {
31         char *state = NULL;
32         int ret = 0;
33         size_t len;
34         GVariant *reply = NULL;
35
36         reply = systemd_get_manager_property(SYSTEMD_DBUS_METHOD_SYSTEM_STATE);
37         if (!reply) {
38                 _E("Failed to get system state: No reply");
39                 goto err;
40         }
41         if (!dh_get_param_from_var(reply, "s", &state)) {
42                 _E("Failed to get system state(%s)", g_variant_get_type_string(reply));
43                 goto err;
44         }
45
46         _I("System state=%s", state);
47
48         len = strlen(state) + 1;
49         if (!strncmp(state, SYSTEMD_STATE_RUNNING, len) ||
50                 !strncmp(state, SYSTEMD_STATE_DEGRADED, len))
51                 ret = 1;
52         else
53         ret = 0;
54
55 err:
56         if (reply)
57                 g_variant_unref(reply);
58         free(state);
59
60         return ret;
61 }