@@ -204,19 +204,21 @@ supervisor_children_set_flag(const char *key, guint32 mask, gboolean enabled)
204
204
return _child_set_flag (sd , mask , enabled );
205
205
}
206
206
207
+ static long
208
+ i64tolong (gint64 i64 )
209
+ {
210
+ long l ;
211
+ if (i64 >= G_MAXLONG )
212
+ return G_MAXLONG ;
213
+ if (i64 < 0 )
214
+ return -1L ;
215
+ l = i64 ;
216
+ return l ;
217
+ }
218
+
207
219
static void
208
220
_child_get_info (struct child_s * c , struct child_info_s * ci )
209
221
{
210
- long i64tolong (gint64 i64 ) {
211
- long l ;
212
- if (i64 >= G_MAXLONG )
213
- return G_MAXLONG ;
214
- if (i64 < 0 )
215
- return -1L ;
216
- l = i64 ;
217
- return l ;
218
- }
219
-
220
222
memset (ci , 0x00 , sizeof (* ci ));
221
223
ci -> key = c -> key ;
222
224
ci -> cmd = c -> command ;
@@ -811,34 +813,32 @@ supervisor_children_register(const gchar *key, const gchar *cmd)
811
813
return TRUE;
812
814
}
813
815
814
- gboolean
815
- supervisor_run_services (void * udata , supervisor_cb_f callback )
816
+ gint
817
+ supervisor_run_services (void * udata , supervisor_run_cb_f callback )
816
818
{
817
- struct child_info_s ci ;
818
819
struct child_s * sd ;
820
+ gint count = 0U ;
819
821
820
- if (!callback ) {
821
- errno = EINVAL ;
822
- return FALSE;
823
- }
822
+ g_assert_nonnull (callback );
824
823
825
824
FOREACH_CHILD (sd ) {
825
+ struct child_info_s ci = {};
826
826
if (FLAG_HAS (sd , MASK_OBSOLETE ))
827
827
continue ;
828
828
_child_get_info (sd , & ci );
829
- callback (udata , & ci );
829
+ if (callback (udata , & ci )) {
830
+ count ++ ;
831
+ }
830
832
}
831
833
832
- return TRUE ;
834
+ return count ;
833
835
}
834
836
835
837
guint
836
838
supervisor_children_kill_disabled (void )
837
839
{
838
- guint count ;
839
840
struct child_s * sd ;
840
-
841
- count = 0U ;
841
+ guint count = 0U ;
842
842
843
843
FOREACH_CHILD (sd ) {
844
844
/* Stop child that needs to be restarted */
@@ -860,12 +860,9 @@ supervisor_children_kill_disabled(void)
860
860
int
861
861
supervisor_children_enable (const char * key , gboolean enable )
862
862
{
863
- struct child_s * sd ;
863
+ g_assert_nonnull ( key ) ;
864
864
865
- if (!key ) {
866
- errno = EINVAL ;
867
- return -1 ;
868
- }
865
+ struct child_s * sd ;
869
866
if (!(sd = supervisor_get_child (key ))) {
870
867
errno = ENOENT ;
871
868
return -1 ;
@@ -948,10 +945,8 @@ supervisor_children_set_limit(const gchar *key, enum supervisor_limit_e what, gi
948
945
{
949
946
struct child_s * sd ;
950
947
951
- if (!key ) {
952
- errno = EINVAL ;
953
- return -1 ;
954
- }
948
+ g_assert_nonnull (key );
949
+
955
950
if (what < SUPERV_LIMIT_THREAD_STACK || what > SUPERV_LIMIT_CORE_SIZE ) {
956
951
errno = EINVAL ;
957
952
return -1 ;
@@ -982,12 +977,10 @@ supervisor_children_set_limit(const gchar *key, enum supervisor_limit_e what, gi
982
977
int
983
978
supervisor_children_set_working_directory (const gchar * key , const gchar * dir )
984
979
{
985
- struct child_s * sd ;
980
+ g_assert_nonnull (key );
981
+ g_assert_nonnull (dir );
986
982
987
- if (!key || !dir ) {
988
- errno = EINVAL ;
989
- return -1 ;
990
- }
983
+ struct child_s * sd ;
991
984
if (!(sd = supervisor_get_child (key ))) {
992
985
errno = ENOENT ;
993
986
return -1 ;
@@ -1005,12 +998,11 @@ int
1005
998
supervisor_children_setenv (const gchar * key , const gchar * envkey ,
1006
999
const gchar * envval , gchar separator )
1007
1000
{
1008
- struct child_s * sd ;
1001
+ g_assert_nonnull (key );
1002
+ g_assert_nonnull (envkey );
1003
+ g_assert_nonnull (envval );
1009
1004
1010
- if (!key || !envkey || !envval ) {
1011
- errno = EINVAL ;
1012
- return -1 ;
1013
- }
1005
+ struct child_s * sd ;
1014
1006
if (!(sd = supervisor_get_child (key ))) {
1015
1007
errno = ENOENT ;
1016
1008
return -1 ;
@@ -1056,23 +1048,21 @@ supervisor_children_inherit_env(const gchar *key)
1056
1048
}
1057
1049
}
1058
1050
1051
+ static void _free (gpointer p1 , gpointer p2 ) { (void ) p2 ; if (p1 ) g_free (p1 ); }
1052
+
1059
1053
int
1060
1054
supervisor_children_clearenv (const gchar * key )
1061
1055
{
1062
- void __free (gpointer p1 , gpointer p2 ) { (void ) p2 ; if (p1 ) g_free (p1 ); }
1063
- struct child_s * sd ;
1056
+ g_assert_nonnull (key );
1064
1057
1065
- if (!key ) {
1066
- errno = EINVAL ;
1067
- return -1 ;
1068
- }
1058
+ struct child_s * sd ;
1069
1059
if (!(sd = supervisor_get_child (key ))) {
1070
1060
errno = ENOENT ;
1071
1061
return -1 ;
1072
1062
}
1073
1063
1074
1064
if (sd -> env ) {
1075
- g_slist_foreach (sd -> env , __free , NULL );
1065
+ g_slist_foreach (sd -> env , _free , NULL );
1076
1066
g_slist_free (sd -> env );
1077
1067
}
1078
1068
sd -> env = NULL ;
@@ -1083,12 +1073,9 @@ supervisor_children_clearenv(const gchar *key)
1083
1073
int
1084
1074
supervisor_children_set_user_flags (const gchar * key , guint32 flags )
1085
1075
{
1086
- struct child_s * sd ;
1076
+ g_assert_nonnull ( key ) ;
1087
1077
1088
- if (!key ) {
1089
- errno = EINVAL ;
1090
- return -1 ;
1091
- }
1078
+ struct child_s * sd ;
1092
1079
if (!(sd = supervisor_get_child (key ))) {
1093
1080
errno = ENOENT ;
1094
1081
return -1 ;
@@ -1102,12 +1089,9 @@ supervisor_children_set_user_flags(const gchar *key, guint32 flags)
1102
1089
int
1103
1090
supervisor_children_del_user_flags (const gchar * key , guint32 flags )
1104
1091
{
1105
- struct child_s * sd ;
1092
+ g_assert_nonnull ( key ) ;
1106
1093
1107
- if (!key ) {
1108
- errno = EINVAL ;
1109
- return -1 ;
1110
- }
1094
+ struct child_s * sd ;
1111
1095
if (!(sd = supervisor_get_child (key ))) {
1112
1096
errno = ENOENT ;
1113
1097
return -1 ;
@@ -1121,12 +1105,9 @@ supervisor_children_del_user_flags(const gchar *key, guint32 flags)
1121
1105
int
1122
1106
supervisor_children_set_group (const gchar * key , const gchar * group )
1123
1107
{
1124
- struct child_s * sd ;
1108
+ g_assert_nonnull ( key ) ;
1125
1109
1126
- if (!key ) {
1127
- errno = EINVAL ;
1128
- return -1 ;
1129
- }
1110
+ struct child_s * sd ;
1130
1111
if (!(sd = supervisor_get_child (key ))) {
1131
1112
errno = ENOENT ;
1132
1113
return -1 ;
@@ -1144,12 +1125,9 @@ supervisor_children_set_group(const gchar *key, const gchar *group)
1144
1125
int
1145
1126
supervisor_children_set_ids (const gchar * key , gint32 uid , gint32 gid )
1146
1127
{
1147
- struct child_s * sd ;
1128
+ g_assert_nonnull ( key ) ;
1148
1129
1149
- if (!key ) {
1150
- errno = EINVAL ;
1151
- return -1 ;
1152
- }
1130
+ struct child_s * sd ;
1153
1131
if (!(sd = supervisor_get_child (key ))) {
1154
1132
errno = ENOENT ;
1155
1133
return -1 ;
@@ -1164,10 +1142,8 @@ supervisor_children_set_ids(const gchar *key, gint32 uid, gint32 gid)
1164
1142
int
1165
1143
supervisor_children_set_delay_sigkill (const char * key , time_t delay )
1166
1144
{
1167
- if (!key ) {
1168
- errno = EINVAL ;
1169
- return -1 ;
1170
- }
1145
+ g_assert_nonnull (key );
1146
+
1171
1147
struct child_s * sd ;
1172
1148
if (!(sd = supervisor_get_child (key ))) {
1173
1149
errno = ENOENT ;
0 commit comments