]> git.sur5r.net Git - bacula/bacula/commitdiff
Win32 fixes + resources array fix
authorKern Sibbald <kern@sibbald.com>
Sun, 27 Jun 2004 11:23:25 +0000 (11:23 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 27 Jun 2004 11:23:25 +0000 (11:23 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1447 91ce42f0-d328-0410-95d8-f526ca767f89

17 files changed:
bacula/src/console/console_conf.c
bacula/src/dird/dird_conf.c
bacula/src/filed/filed_conf.c
bacula/src/filed/status.c
bacula/src/filed/win32/Makefile.in
bacula/src/filed/win32/Makefile.mingw
bacula/src/filed/win32/warn.ico [new file with mode: 0644]
bacula/src/filed/win32/winmain.cpp
bacula/src/filed/win32/winres.h
bacula/src/filed/win32/winres.rc
bacula/src/filed/win32/winservice.cpp
bacula/src/filed/win32/wintray.cpp
bacula/src/filed/win32/wintray.h
bacula/src/jcr.h
bacula/src/lib/bnet_server.c
bacula/src/lib/jcr.c
bacula/src/stored/stored_conf.c

index 89c31d0705d3f05bbcc057b43470056bfd44ab85..4a377dfa661d4610da59acddfbd24d160330a8f5 100644 (file)
@@ -47,7 +47,7 @@
  */
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 /* Forward referenced subroutines */
index fa8d41568fa53379f5b1f98a9106d2d52b4f4d5f..18591c256ff9aa5d494267fc65e8a99d6ef9426d 100644 (file)
@@ -50,7 +50,7 @@
  */
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 /* Imported subroutines */
index c4c62fe620296b90ef942953bebd459713dc0baf..23d8e627805ecc1313ec4acc3c4ee587c3a042ec 100644 (file)
@@ -51,7 +51,7 @@
  */
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;
 
 
index 715a80af69d5c1c9b53d5baedf3ea39016961151..0c16b08460bd2ae1ff401b9e9d8cdf998e7de28b 100755 (executable)
@@ -306,7 +306,6 @@ static const char *level_to_str(int level)
 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
 #include <windows.h>
 
-static char buf[100];
 int bacstat = 0;
 
 struct s_win32_arg {
@@ -325,8 +324,7 @@ static void win32_sendit(const char *msg, int len, void *marg)
        // when compiling with visual studio some strings are read-only 
        // and cause access violations. So we creat a tmp copy.
        char *_msg = (char *)alloca(len);
-       strncpy(_msg, msg, len-1);
-       _msg[len-1] = 0;
+       bstrncpy(_msg, msg, len);
        msg = _msg;
    }
    SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg);
@@ -346,45 +344,54 @@ void FillStatusBox(HWND hwnd, int idlist)
    do_status(win32_sendit, (void *)&arg);
 }
 
-char *bac_status(int stat)
+char *bac_status(char *buf, int buf_len)
 {
    JCR *njcr;
    const char *termstat = _("Bacula Idle");
    struct s_last_job *job;
+   int stat = 0;                     /* Idle */
 
-   bacstat = 0;
    if (!last_jobs) {
-      return _("Bacula Terminated");
+      goto done;
+   }
+   Dmsg0(1000, "Begin bac_status jcr loop.\n");
+   lock_jcr_chain();
+   foreach_jcr(njcr) {
+      if (njcr->JobId != 0) {
+        stat = JS_Running;
+         termstat = _("Bacula Running");
+        free_locked_jcr(njcr);
+        break;
+      }
+      free_locked_jcr(njcr);
+   }
+   unlock_jcr_chain();
+   if (stat != 0) {
+      goto done;
    }
    if (last_jobs->size() > 0) {
       job = (struct s_last_job *)last_jobs->last();
+      stat = job->JobStatus;
       switch (job->JobStatus) {
       case JS_Canceled:
-        bacstat = -1;
          termstat = _("Last Job Canceled");
         break;
       case JS_ErrorTerminated:
-        bacstat = -1;
          termstat = _("Last Job Failed");
         break;
       default:
+        if (job->Errors) {
+            termstat = _("Last Job had Errors");
+        }
         break;
       }
    }
-   Dmsg0(1000, "Begin bac_status jcr loop.\n");
-   lock_jcr_chain();
-   foreach_jcr(njcr) {
-      if (njcr->JobId != 0) {
-        bacstat = 1;
-         termstat = _("Bacula Running");
-        free_locked_jcr(njcr);
-        break;
-      }
-      free_locked_jcr(njcr);
-   }
-   unlock_jcr_chain();
    Dmsg0(1000, "End bac_status jcr loop.\n");
-   bstrncpy(buf, termstat, sizeof(buf));
+done:
+   bacstat = stat;
+   if (buf) {
+      bstrncpy(buf, termstat, sizeof(buf));
+   }
    return buf;
 }
 
index d25f21dd8a645f54d0e375bf3fc8f77970294b2c..d7b01e6b73ca50a55d39629a705439bd82cf0819 100755 (executable)
@@ -46,7 +46,7 @@ win32: winlib.a
 winlib.a: $(BACOBJS) winres.res
        ar rcs $@ $(BACOBJS)
 
-winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico
+winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico warn.ico
        windres $< -O coff -o $@
 
 winmain.o: winmain.cpp winbacula.h
index 978699c2d5b6949f2d3f0fcec169805656dfcfb1..4a3e36ff772c2dc1c12afc44abe86d71d11bf6db 100644 (file)
@@ -46,7 +46,7 @@ win32: winlib.a
 winlib.a: $(BACOBJS) winres.res
        ar rcs $@ $(BACOBJS)
 
-winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico
+winres.res: winres.rc bacula.ico winres.h idle.ico running.ico error.ico warn.ico
        windres -DHAVE_MINGW $< -O coff -o $@
 
 winmain.o: winmain.cpp winbacula.h
diff --git a/bacula/src/filed/win32/warn.ico b/bacula/src/filed/win32/warn.ico
new file mode 100644 (file)
index 0000000..26e1d39
Binary files /dev/null and b/bacula/src/filed/win32/warn.ico differ
index 625146ae20f00592c753f3153210fc7d8406d8ca..6cbf0309e15b4411f597d80fc1126c9106739937 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2000-2003 Kern Sibbald and John Walker
+   Copyright (C) 2000-2004 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -18,7 +18,6 @@
 
    This file is patterned after the VNC Win32 code by ATT
   
-   Copyright (2000) Kern E. Sibbald
 */
 
 #ifndef HAVE_WIN32
index a1f52e9f260f710f3818ae3147ecb001a5dca4d2..66a84c1b86060e4f174a348f72d831c270a6a215 100755 (executable)
@@ -7,7 +7,9 @@
 #define IDI_IDLE                        101
 #define IDI_RUNNING                     102
 #define IDI_JOB_ERROR                   103
-#define IDR_TRAYMENU                    104
+#define IDI_JOB_WARNING                 104
+#define IDR_TRAYMENU                    105
+#define IDB_BACULABMP                   106
 
 #define IDC_LIST                        1000
 #define IDC_NONYET_LABEL                1006
@@ -42,4 +44,3 @@
 #define IDD_EVENTS                      203
 
 
-#define IDB_BACULABMP                   106
index e4e997b1419e7849820c07552021618bc3a484d8..3c19cc85ef9191756b4c6c2b00872ce2c6c84763 100644 (file)
@@ -14,6 +14,7 @@ IDI_BACULA              ICON    DISCARDABLE     "bacula.ico"
 IDI_IDLE                ICON    DISCARDABLE     "idle.ico"
 IDI_RUNNING             ICON    DISCARDABLE     "running.ico"
 IDI_JOB_ERROR           ICON    DISCARDABLE     "error.ico"
+IDI_JOB_WARNING         ICON    DISCARDABLE     "warn.ico"
 
 /////////////////////////////////////////////////////////////////////////////
 //
index 2bac945a27ca05854606ced25604669d0be6b404..0111087d2f49dfa78c64cd3d6fd37419de19aa7e 100755 (executable)
@@ -38,6 +38,7 @@
 
 
 #include <lmcons.h>
+#undef PASCAL
 #include "winbacula.h"
 #include "winservice.h"
 #include "wintray.h"
index 933e613573cb40c6b50508ce648db566178c1099..3105220eed8cbc994c8c39830ee164fe116602ca 100755 (executable)
@@ -25,7 +25,7 @@
 // by Kern E. Sibbald.  Many thanks to ATT and James Weatherall,
 // the original author, for providing an excellent template.
 //
-// Copyright (2000-2003) Kern E. Sibbald
+// Copyright 2000-2004, Kern E. Sibbald
 //
 
 
@@ -41,6 +41,8 @@
 // Header
 
 #include "wintray.h"
+#include "bacula.h"
+#include "jcr.h"
 
 // Constants
 #ifdef properties_implemented
@@ -55,7 +57,7 @@ const UINT MENU_ADD_CLIENT_MSG = RegisterWindowMessage("Bacula.AddClient.Message
 const char *MENU_CLASS_NAME = "Bacula Tray Icon";
 
 extern void terminate_filed(int sig);
-extern char *bac_status(int stat);
+extern char *bac_status(char *buf, int buf_len);
 extern int bacstat;
 
 // Implementation
@@ -102,9 +104,10 @@ bacMenu::bacMenu()
    SetTimer(m_hwnd, 1, 5000, NULL);
 
    // Load the icons for the tray
-   m_idle_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_IDLE));
+   m_idle_icon    = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_IDLE));
    m_running_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_RUNNING));
-   m_error_icon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_ERROR));
+   m_error_icon   = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_ERROR));
+   m_warn_icon    = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_JOB_WARNING));
 
    // Load the popup menu
    m_hmenu = LoadMenu(hAppInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
@@ -139,23 +142,42 @@ bacMenu::DelTrayIcon()
 void
 bacMenu::UpdateTrayIcon(int bacstat)
 {
-   (void *)bac_status(0);
+   (void *)bac_status(NULL, 0);
    SendTrayMsg(NIM_MODIFY, bacstat);
 }
 
 void
 bacMenu::SendTrayMsg(DWORD msg, int bacstat)
 {
+   struct s_last_job *job;
+   
    // Create the tray icon message
    m_nid.hWnd = m_hwnd;
    m_nid.cbSize = sizeof(m_nid);
    m_nid.uID = IDI_BACULA;                  // never changes after construction
-   if (bacstat == 0)
+   switch (bacstat) {
+   case 0:
       m_nid.hIcon = m_idle_icon;
-   else if (bacstat == 1)
+      break;
+   case JS_Running:
       m_nid.hIcon = m_running_icon;
-   else if (bacstat < 0)
+      break;
+   case JS_ErrorTerminated:
       m_nid.hIcon = m_error_icon;
+      break;
+   default:
+      if (last_jobs->size() > 0) {
+         job = (struct s_last_job *)last_jobs->last();
+         if (job->Errors) {
+            m_nid.hIcon = m_warn_icon;
+         } else {
+            m_nid.hIcon = m_idle_icon;
+         }
+      } else {
+         m_nid.hIcon = m_idle_icon;
+      }
+      break;
+   }
 
    m_nid.uFlags = NIF_ICON | NIF_MESSAGE;
    m_nid.uCallbackMessage = WM_TRAYNOTIFY;
@@ -168,7 +190,7 @@ bacMenu::SendTrayMsg(DWORD msg, int bacstat)
 
    // Try to add the Bacula status to the tip string, if possible
    if (m_nid.uFlags & NIF_TIP) {
-       strncpy(m_nid.szTip, bac_status(0), (sizeof(m_nid.szTip)-1));
+       bac_status(m_nid.szTip, sizeof(m_nid.szTip));
    }
 
    // Send the message
@@ -201,24 +223,12 @@ LRESULT CALLBACK bacMenu::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP
       if (bacService::RunningAsService()) {
           // Attempt to add the icon if it's not already there
           _this->AddTrayIcon();
-          // Trigger a check of the current user
-//        PostMessage(hwnd, WM_USERCHANGED, 0, 0);
       }
 
       // Update the icon
       _this->UpdateTrayIcon(bacstat);
      break;
 
-#ifdef xxx_needed
-
-   // DEAL WITH NOTIFICATIONS FROM THE SERVER:
-   case WM_SRV_CLIENT_AUTHENTICATED:
-   case WM_SRV_CLIENT_DISCONNECT:
-      // Adjust the icon accordingly
-      _this->UpdateTrayIcon(bacstat);
-      return 0;
-#endif
-
    // STANDARD MESSAGE HANDLING
    case WM_CREATE:
       return 0;
@@ -311,61 +321,32 @@ LRESULT CALLBACK bacMenu::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lP
       return 0;
 
    case WM_QUERYENDSESSION:
-           // Are we running as a system service?
-           // Or is the system shutting down (in which case we should check anyway!)
-           if ((!bacService::RunningAsService()) || (lParam == 0)) {
-                   // No, so we are about to be killed
+      // Are we running as a system service?
+      // Or is the system shutting down (in which case we should check anyway!)
+      if ((!bacService::RunningAsService()) || (lParam == 0)) {
+         // No, so we are about to be killed
 
-                   // If there are remote connections then we should verify
-                   // that the user is happy about killing them.
+         // If there are remote connections then we should verify
+         // that the user is happy about killing them.
 
-                   // Finally, post a quit message, just in case
-                   PostQuitMessage(0);
-                   return TRUE;
-           }
-
-           // Tell the OS that we've handled it anyway
-//         PostQuitMessage(0);
-           return TRUE;
+         // Finally, post a quit message, just in case
+         PostQuitMessage(0);
+         return TRUE;
+      }
+      return TRUE;
 
    
    default:
-           if (iMsg == MENU_ABOUTBOX_SHOW) {
-                   // External request to show our About dialog
-                   PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0);
-                   return 0;
-           }
-           if (iMsg == MENU_STATUS_SHOW) {
-                   // External request to show our status
-                   PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_STATUS, 0), 0);
-                   return 0;
-           }
-
-#ifdef xxx_needed
-           if (iMsg == MENU_EVENTS_SHOW) {
-                   // External request to show our Events dialogue
-                   PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_EVENTS, 0), 0);
-                   return 0;
-           }
-
-           if (iMsg == MENU_SERVICEHELPER_MSG) {
-                   // External ServiceHelper message.
-                   // This message holds a process id which we can use to
-                   // impersonate a specific user.  In doing so, we can load their
-                   // preferences correctly
-                   bacService::ProcessUserHelperMessage(wParam, lParam);
-
-                   // - Trigger a check of the current user
-                   PostMessage(hwnd, WM_USERCHANGED, 0, 0);
-                   return 0;
-           }
-           if (iMsg == MENU_ADD_CLIENT_MSG) {
-                   // Add Client message.  This message includes an IP address
-                   // of a listening client, to which we should connect.
-
-                   return 0;
-           }
-#endif
+      if (iMsg == MENU_ABOUTBOX_SHOW) {
+         // External request to show our About dialog
+         PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0);
+         return 0;
+      }
+      if (iMsg == MENU_STATUS_SHOW) {
+         // External request to show our status
+         PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_STATUS, 0), 0);
+         return 0;
+      }
    }
 
    // Message not recognised
index 0b210282af26938249d50cc99bcdf9a9b3698efb..54f418355b004fcd8e25fd6bccfb4ee738151e7b 100755 (executable)
@@ -72,21 +72,22 @@ protected:
 protected:
 
    // About dialog for this server
-   bacAbout                m_about;
+   bacAbout  m_about;
 
    // Status dialog for this server
-   bacStatus               m_status;
+   bacStatus m_status;
 
-   bacEvents               m_events;
+   bacEvents m_events;
 
-   HWND                    m_hwnd;
-   HMENU                   m_hmenu;
-   NOTIFYICONDATA          m_nid;
+   HWND  m_hwnd;
+   HMENU m_hmenu;
+   NOTIFYICONDATA m_nid;
 
    // The icon handles
-   HICON                   m_idle_icon;
-   HICON                   m_running_icon;
-   HICON                   m_error_icon;
+   HICON m_idle_icon;
+   HICON m_running_icon;
+   HICON m_error_icon;
+   HICON m_warn_icon;
 };
 
 
index 1c9471e9aaa0234871b9b4ec13fba704bbfdec4f..dbb707663ded7e9dfd6210f78c2b1ba71667698a 100644 (file)
@@ -261,7 +261,7 @@ struct JCR {
  */
 struct s_last_job {
    dlink link;
-   int xNumJobs;                      /* no longer used */
+   int Errors;                        /* FD/SD errors */
    int JobType;
    int JobStatus;
    int JobLevel;
index 74903b83fceef3736501a4dac9add1f65b7d4440..f4cc0575270b073a3dbead2d3690ffbd7b98db14 100644 (file)
@@ -134,7 +134,7 @@ bnet_thread_server(char *bind_addr, int port, int max_clients, workq_t *client_w
    for (;!quit;) {
       fd_set sockset;
       FD_ZERO(&sockset);
-      FD_SET(sockfd, &sockset);
+      FD_SET((unsigned)sockfd, &sockset);
       errno = 0;
       if ((stat = select(sockfd+1, &sockset, NULL, NULL, NULL)) < 0) {
         if (errno == EINTR || errno == EAGAIN) {
@@ -281,7 +281,7 @@ bnet_accept(BSOCK *bsock, char *who)
     * Wait for a connection from the client process.
     */
    FD_ZERO(&sockset);
-   FD_SET(bsock->fd, &sockset);
+   FD_SET((unsigned)bsock->fd, &sockset);
 
    for (;;) {
       /* 
index eebb5244de8893ac96d126477b97aaba6fbeb58b..6fb681a661cd198c53ac71b5481f5708715b451b 100755 (executable)
@@ -263,6 +263,7 @@ static void free_common_jcr(JCR *jcr)
    case JT_RESTORE:
    case JT_ADMIN:
       num_jobs_run++;
+      last_job.Errors = jcr->Errors;
       last_job.JobType = jcr->JobType;
       last_job.JobId = jcr->JobId;
       last_job.VolSessionId = jcr->VolSessionId;
index b0f604c1dc4d9e31eac3e1a8ba74c8f71314ecde..2cf95e805f35a15b495913243439ba0f5075ef05 100644 (file)
@@ -35,7 +35,7 @@ extern int debug_level;
 /* First and last resource ids */
 int r_first = R_FIRST;
 int r_last  = R_LAST;
-static RES *sres_head[R_LAST - R_FIRST];
+static RES *sres_head[R_LAST - R_FIRST + 1];
 RES **res_head = sres_head;