Skip to content

Commit c5ac09e

Browse files
committed
session server UPDATE nc_server_destroy return value
Change return type from void to int to allow callers to handle cleanup failures. Also update nc_server_notif_cert_expiration_thread_stop to return error code so that nc_server_destroy can properly propagate errors.
1 parent 434c428 commit c5ac09e

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/session_server.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,9 +1296,10 @@ nc_server_init(void)
12961296
return -1;
12971297
}
12981298

1299-
API void
1299+
API int
13001300
nc_server_destroy(void)
13011301
{
1302+
int rc = 0;
13021303
int config_update_locked = 0;
13031304
enum nc_rwlock_mode config_lock_mode = NC_RWLOCK_NONE;
13041305
uint32_t i;
@@ -1315,7 +1316,10 @@ nc_server_destroy(void)
13151316

13161317
#ifdef NC_ENABLED_SSH_TLS
13171318
/* destroy the certificate expiration notification thread */
1318-
nc_server_notif_cert_expiration_thread_stop(1);
1319+
if ((rc = nc_server_notif_cert_expiration_thread_stop(1))) {
1320+
ERR(NULL, "%s: failed to stop certificate expiration notification thread.", __func__);
1321+
goto cleanup;
1322+
}
13191323
#endif /* NC_ENABLED_SSH_TLS */
13201324

13211325
/* CONFIG UPDATE LOCK, continue on error */
@@ -1382,6 +1386,9 @@ nc_server_destroy(void)
13821386
fclose(server_opts.tls_keylog_file);
13831387
}
13841388
#endif /* NC_ENABLED_SSH_TLS */
1389+
1390+
cleanup:
1391+
return rc;
13851392
}
13861393

13871394
API int
@@ -4753,15 +4760,15 @@ nc_server_notif_cert_expiration_thread_start(nc_cert_exp_notif_clb cert_exp_noti
47534760
return ret;
47544761
}
47554762

4756-
API void
4763+
API int
47574764
nc_server_notif_cert_expiration_thread_stop(int wait)
47584765
{
47594766
int r;
47604767
pthread_t tid;
47614768

47624769
/* LOCK */
47634770
if (nc_mutex_lock(&server_opts.cert_exp_notif.lock, NC_CERT_EXP_LOCK_TIMEOUT, __func__) != 1) {
4764-
return;
4771+
return 1;
47654772
}
47664773
tid = server_opts.cert_exp_notif.tid;
47674774

@@ -4780,12 +4787,14 @@ nc_server_notif_cert_expiration_thread_stop(int wait)
47804787
}
47814788
if (r) {
47824789
ERR(NULL, "Stopping the certificate expiration notification thread failed (%s).", strerror(r));
4790+
return 1;
47834791
}
47844792
} else {
47854793
/* thread is not running */
47864794
/* UNLOCK */
47874795
nc_mutex_unlock(&server_opts.cert_exp_notif.lock, __func__);
47884796
}
4797+
return 0;
47894798
}
47904799

47914800
#endif /* NC_ENABLED_SSH_TLS */

src/session_server.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ int nc_server_init(void);
144144
/**
145145
* @brief Destroy any dynamically allocated libssh and/or libssl/libcrypto and
146146
* server resources.
147+
*
148+
* @return 0 on success, 1 on error - all resources could not be freed safely.
147149
*/
148-
void nc_server_destroy(void);
150+
int nc_server_destroy(void);
149151

150152
/**
151153
* @brief Initialize a context which can serve as a default server context.
@@ -669,8 +671,9 @@ int nc_server_notif_cert_expiration_thread_start(nc_cert_exp_notif_clb cert_exp_
669671
* @brief Stop the certificate expiration notification thread.
670672
*
671673
* @param[in] wait Boolean representing whether to block and wait for the thread to finish.
674+
* @return 0 on success, 1 on error.
672675
*/
673-
void nc_server_notif_cert_expiration_thread_stop(int wait);
676+
int nc_server_notif_cert_expiration_thread_stop(int wait);
674677

675678
#endif /* NC_ENABLED_SSH_TLS */
676679

0 commit comments

Comments
 (0)