X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ntsimulator%2Fntsim-ng%2Futils%2Fsys_utils.c;h=9b499959622f9abd8cc33d6ecc82b5bd838fbf49;hb=caec2fcb18e829420672509fe5e356b48d0c3840;hp=1007b623f7137766bf31157b5d18dab37348b972;hpb=96526af57d1c3026430e11cfe899e50629a91296;p=sim%2Fo1-interface.git diff --git a/ntsimulator/ntsim-ng/utils/sys_utils.c b/ntsimulator/ntsim-ng/utils/sys_utils.c index 1007b62..9b49995 100644 --- a/ntsimulator/ntsim-ng/utils/sys_utils.c +++ b/ntsimulator/ntsim-ng/utils/sys_utils.c @@ -68,7 +68,7 @@ void file_touch(const char *fname, const char *content) { FILE *f = fopen(fname, "w"); if(f == 0) { - log_error("fopen failed"); + log_error("fopen failed\n"); return; } @@ -88,12 +88,13 @@ char *file_read_content(const char *fname) { fseek(f, 0, SEEK_END); length = ftell(f); fseek(f, 0, SEEK_SET); - buffer = (char*)malloc(sizeof(char) * length); + buffer = (char*)malloc(sizeof(char) * (length + 1)); if(buffer) { fread(buffer, 1, length, f); } fclose(f); } + buffer[length] = 0; return buffer; } @@ -260,8 +261,8 @@ bool check_port_open(const char *host, uint16_t port) { } freeaddrinfo(res); - if(returnStatus == 0) { - close(simpleSocket); + close(simpleSocket); + if(returnStatus == 0) { return true; } @@ -423,7 +424,7 @@ char *read_key(const char *filename) { fp = fopen(filename, "r"); if(fp == 0) { - log_error("could not open file %s", filename); + log_error("could not open file %s\n", filename); return 0; } @@ -439,7 +440,7 @@ char *read_key(const char *filename) { if(key_string) { key_string = (char *)realloc(key_string, strlen(key_string) + read + 1); if(key_string == 0) { - log_error("bad allocation"); + log_error("bad allocation\n"); free(line); return 0; } @@ -449,7 +450,7 @@ char *read_key(const char *filename) { else { key_string = strdup(line); if(key_string == 0) { - log_error("bad allocation"); + log_error("bad allocation\n"); free(line); return 0; } @@ -468,3 +469,19 @@ char *read_key(const char *filename) { return key_string; } + +void vsftp_daemon_init(void) { + system("/usr/sbin/vsftpd &"); +} + +void vsftp_daemon_deinit(void) { + system("killall -9 vsftpd"); +} + +void sftp_daemon_init(void) { + system("/usr/sbin/sshd -D &"); +} + +void sftp_daemon_deinit(void) { + system("killall -9 sshd"); +}