]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/lib/status.h
authorAlain Spineux <alain@baculasystems.com>
Thu, 23 Apr 2020 14:33:12 +0000 (16:33 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:17 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Mar 19 11:31:25 2018 +0100

    Fix compilation on Solaris

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Feb 19 09:36:03 2018 +0100

    Fix compiler warning with rlimit display in list_resource_limits

Author: Alain Spineux <alain@baculasystems.com>
Date:   Tue Mar 21 15:10:06 2017 +0100

    add list_resource_limits() to daemon status (part1)

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Jan 28 09:15:23 2014 +0100

    Implement .api v2 and use computer friendly output to status commands.

    For example, we can use the following code:

    static void api_list_dir_status_header(UAContext *ua)
    {
       OutputWriter wt;
       ua->send_msg("%s",
        wt.get_output(
         OT_STRING, "name",        my_name,
         OT_STRING, "version",     VERSION " (" BDATE ")",
         OT_STRING, "uname",       HOST_OS " " DISTNAME " " DISTVER,
         OT_UTIME,  "started",     daemon_start_time,
         OT_UTIME,  "reloaded",    last_reload_time,
         OT_INT,    "jobs_run",    num_jobs_run,
         OT_INT,    "jobs_running",job_count(),
         OT_END
           ));
    }

    It will display

    name=bacula-dir
    version=6.6.3 (12Dec13)
    uname=....

    The OutputWriter class can be configured to use a custom
    separator (\t or \n for example), custom date format, and
    will handle basic formating such as time, string, integer,
    list of strings, etc...

bacula/src/lib/status.h

index 1fd33b2151d60da1129ecea7627535f15ca2b5ed..f82d5c38e8b56df4ba4be8ff5f7d768580123046 100644 (file)
@@ -198,6 +198,73 @@ static void list_terminated_jobs(STATUS_PKT *sp)
    }
 }
 
+/* common to SD/FD/DIR */
+static void list_resource_limits(STATUS_PKT *sp, int64_t l_nofile, int64_t l_memlock)
+{
+#ifdef HAVE_GETRLIMIT
+   OutputWriter ow(sp->api_opts);
+   POOL_MEM msg(PM_MESSAGE), msg_status(PM_MESSAGE);
+   struct rlimit rlim;
+   int64_t nofile=-1, memlock=-1;
+   char nofile_s[128], memlock_s[128];
+   *nofile_s = *memlock_s = '\0';
+
+   msg_status.strcpy("");
+#ifdef RLIMIT_NOFILE
+   if (getrlimit(RLIMIT_NOFILE, &rlim)==0) {
+      if (rlim.rlim_cur == RLIM_INFINITY) {
+         nofile=-1;
+         bstrncpy(nofile_s, "unlimited", sizeof(nofile_s));
+      } else {
+         nofile=rlim.rlim_cur;
+         edit_int64(nofile, nofile_s);
+         if (l_nofile > 0 && nofile<l_nofile) {
+            msg_status.strcat("nofile ");
+         }
+      }
+   }
+#endif
+#ifdef RLIMIT_MEMLOCK
+   if (getrlimit(RLIMIT_MEMLOCK, &rlim)==0) {
+      if (rlim.rlim_cur == RLIM_INFINITY) {
+         memlock=-1;
+         bstrncpy(memlock_s, "unlimited", sizeof(memlock_s));
+      } else {
+         memlock=rlim.rlim_cur;
+         edit_int64(memlock, memlock_s);
+         if (l_memlock > 0 && memlock<l_memlock) {
+            msg_status.strcat("memlock ");
+         }
+      }
+   }
+#endif
+
+   if (strlen(msg_status.c_str())>0) {
+      strip_trailing_junk(msg_status.c_str());
+   } else {
+      msg_status.strcpy("ok");
+   }
+
+   if (sp->api > 1) {
+      OutputWriter ow(sp->api_opts);
+      char *p;
+      ow.start_group("ulimit");
+      ow.get_output(    OT_START_OBJ,
+                        OT_INT64,   "nofile",   nofile,
+                        OT_INT64,   "memlock",  memlock,
+                        OT_STRING,  "status",   msg_status.c_str(),
+                        OT_END_OBJ,
+                        OT_END);
+      p = ow.end_group(); // dedupengine
+      sendit(p, strlen(p), sp);
+   } else {
+      int len = Mmsg(msg, _(" Ulimits: nofile=%s memlock=%s status=%s\n"),
+            nofile_s, memlock_s, msg_status.c_str());
+      sendit(msg.c_str(), len, sp);
+   }
+#endif
+}
+
 #if defined(HAVE_WIN32)
 int bacstat = 0;