vip-process: print VIP fail log on console 14/259814/5 accepted/tizen/unified/20210616.132434 submit/tizen/20210616.024518 submit/tizen/20210616.025608
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 15 Jun 2021 06:26:00 +0000 (15:26 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Wed, 16 Jun 2021 02:13:30 +0000 (11:13 +0900)
Change-Id: I82a748248f2c2f62cb49548edaae0cd849425ed0
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/vip-agent/vip-process.c

index 3782027..e48892b 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdarg.h>
 #include <dirent.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 static char **arg_vip_proc_names = NULL;
 static char **arg_vip_systemd_services = NULL;
 
+
+/* print log on console */
+static void vip_print_console(const char *format, ...)
+{
+       FILE *fp = NULL;
+       char buffer[256] = {0, };
+       int eno;
+       va_list ap;
+
+       fp = fopen("/dev/console", "a");
+       if (!fp) {
+               eno = errno;
+
+               va_start(ap, format);
+               vsnprintf(buffer, 256, format, ap);
+               va_end(ap);
+
+               errno = eno;
+               _E("%s(failed to print log on console, %m)", buffer);
+
+               return;
+       }
+
+       va_start(ap, format);
+       vfprintf(fp, format, ap);
+       va_end(ap);
+
+       fprintf(fp, "\n");
+
+       fclose(fp);
+}
+
 /* copy of libsyscommon/libsystemd.c: systemd_get_unit_dbus_path() */
 static int vip_get_escaped_name(const char *unit, char **escaped)
 {
@@ -160,7 +193,7 @@ static bool vip_check_all(void)
        FOREACH_STRV(pname, arg_vip_proc_names) {
                pid = find_pid_from_cmdline(*pname);
                if (pid < 0) {
-                       _E("VIP %s not found", *pname);
+                       vip_print_console("[VIP FAILED] %s is not running", *pname);
                        ret = false;
                }
        }
@@ -177,7 +210,7 @@ static bool vip_check_all(void)
                 * been active before. Therefore, it is necessary to check
                 * whether it is still alive. */
                if (pid == 0 || kill(pid, 0) != 0) {
-                       _E("VIP %s not found", *pname);
+                       vip_print_console("[VIP FAILED] %s is not running", *pname);
                        ret = false;
                }
        }
@@ -187,7 +220,7 @@ static bool vip_check_all(void)
 
 static void vip_force_reboot(void)
 {
-       _E("VIP force reboot.");
+       vip_print_console("[VIP FAILED] Force reboot");
        execl("/usr/bin/vip-release-agent", "/usr/bin/vip-release-agent", NULL);
 
        _E("Failed to execute vip-release-agent");