Add VES stndDefined PM and subscription for O-DU.
[sim/o1-interface.git] / ntsimulator / ntsim-ng / utils / sys_utils.c
index 1007b62..9b49995 100644 (file)
@@ -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");
+}