Skip to content

Commit 0e4faa5

Browse files
jaeyun-jungmyungjoo
authored andcommitted
[Daemon] handle error code
Clearly handle error code when initializing mlops-agent daemon. Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
1 parent cd3206d commit 0e4faa5

File tree

7 files changed

+53
-23
lines changed

7 files changed

+53
-23
lines changed

daemon/main.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ postinit (void)
5151
signal (SIGTERM, handle_sigterm);
5252

5353
ret = gdbus_get_name (DBUS_ML_BUS_NAME);
54-
if (ret < 0)
54+
if (ret < 0) {
55+
ml_loge ("Failed to get mlops-agent dbus.");
5556
return ret;
57+
}
5658

5759
return 0;
5860
}
@@ -104,23 +106,28 @@ main (int argc, char **argv)
104106
{
105107
int ret = 0;
106108

107-
if (parse_args (&argc, &argv)) {
108-
ret = -EINVAL;
109+
ret = parse_args (&argc, &argv);
110+
if (ret < 0)
109111
goto error;
110-
}
111112

112113
/* path to database */
113114
if (!db_path)
114115
db_path = g_strdup (DB_PATH);
115116

116-
ml_agent_initialize (db_path);
117+
ret = ml_agent_initialize (db_path);
118+
if (ret < 0)
119+
goto error;
117120

118121
g_mainloop = g_main_loop_new (NULL, FALSE);
119-
gdbus_get_system_connection (is_session);
122+
ret = gdbus_get_system_connection (is_session);
123+
if (ret < 0)
124+
goto error;
120125

121126
init_modules (NULL);
122-
if (postinit () < 0)
123-
ml_loge ("cannot init system");
127+
128+
ret = postinit ();
129+
if (ret < 0)
130+
goto error;
124131

125132
g_main_loop_run (g_mainloop);
126133
exit_modules (NULL);
@@ -133,7 +140,6 @@ main (int argc, char **argv)
133140
ml_agent_finalize ();
134141

135142
is_session = verbose = FALSE;
136-
g_free (db_path);
137-
db_path = NULL;
143+
g_clear_pointer (&db_path, g_free);
138144
return ret;
139145
}

daemon/mlops-agent-internal.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,27 @@
1616
/**
1717
* @brief Internal function to initialize mlops-agent interface.
1818
*/
19-
void
19+
int
2020
ml_agent_initialize (const char *db_path)
2121
{
22-
g_assert (STR_IS_VALID (db_path));
23-
g_assert (g_file_test (db_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR));
22+
int ret;
23+
24+
if (!STR_IS_VALID (db_path) ||
25+
!g_file_test (db_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
26+
ml_loge ("Failed to initialize mlops-agent, database path (%s) is invalid.", db_path);
27+
return -EINVAL;
28+
}
29+
30+
ret = svcdb_initialize (db_path);
31+
if (ret < 0)
32+
goto error;
33+
34+
ret = mlops_node_initialize ();
2435

25-
svcdb_initialize (db_path);
26-
mlops_node_initialize ();
36+
error:
37+
if (ret < 0)
38+
ml_agent_finalize ();
39+
return ret;
2740
}
2841

2942
/**

daemon/mlops-agent-internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ typedef enum
3232
/**
3333
* @brief Internal function to initialize mlops-agent interface.
3434
*/
35-
void ml_agent_initialize (const char *db_path);
35+
int ml_agent_initialize (const char *db_path);
3636

3737
/**
3838
* @brief Internal function to finalize mlops-agent interface.

daemon/mlops-agent-node.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,24 @@ _mlops_node_free (gpointer data)
115115
/**
116116
* @brief Initialize mlops node info.
117117
*/
118-
void
118+
int
119119
mlops_node_initialize (void)
120120
{
121+
int ret = 0;
122+
121123
G_LOCK (mlops_node_table);
122124
if (!g_mlops_node_table) {
123125
g_mlops_node_table = g_hash_table_new_full (g_int64_hash, g_int64_equal,
124126
g_free, _mlops_node_free);
125127
}
126-
g_assert (g_mlops_node_table != NULL);
128+
129+
if (g_mlops_node_table == NULL) {
130+
ml_logw ("Failed to initialize mlops-agent node table.");
131+
ret = -EIO;
132+
}
127133
G_UNLOCK (mlops_node_table);
134+
135+
return ret;
128136
}
129137

130138
/**

daemon/mlops-agent-node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ typedef enum
3535
/**
3636
* @brief Initialize mlops node info.
3737
*/
38-
void mlops_node_initialize (void);
38+
int mlops_node_initialize (void);
3939

4040
/**
4141
* @brief Finalize mlops node info.

daemon/service-db-util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
G_BEGIN_DECLS
2020

21-
void svcdb_initialize (const gchar *path);
21+
gint svcdb_initialize (const gchar *path);
2222
void svcdb_finalize (void);
2323
gint svcdb_pipeline_set (const gchar *name, const gchar *description);
2424
gint svcdb_pipeline_get (const gchar *name, gchar **description);

daemon/service-db.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,11 @@ G_BEGIN_DECLS
868868
/**
869869
* @brief Initialize the service-db.
870870
*/
871-
void
871+
gint
872872
svcdb_initialize (const gchar *path)
873873
{
874+
gint ret = 0;
875+
874876
if (g_svcdb_instance) {
875877
ml_logw ("ML service DB is already opened, close old DB.");
876878
svcdb_finalize ();
@@ -880,11 +882,12 @@ svcdb_initialize (const gchar *path)
880882
g_svcdb_instance = new MLServiceDB (path);
881883
g_svcdb_instance->connectDB ();
882884
} catch (const std::exception &e) {
883-
ml_loge ("%s", e.what ());
885+
ml_loge ("Failed to initialize database: %s", e.what ());
884886
svcdb_finalize ();
887+
ret = -EIO;
885888
}
886889

887-
g_assert (g_svcdb_instance);
890+
return ret;
888891
}
889892

890893
/**

0 commit comments

Comments
 (0)