~ubuntu-branches/debian/sid/apt-dater/sid

« back to all changes in this revision

Viewing changes to src/stats.c

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2015-07-07 17:33:08 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20150707173308-7rkjhxnlq7gsykif
Tags: 1.0.2-1
* New upstream release.
  - Set the default of the opt-cmd-flags host option to "-t" since this is
    essential.
    Closes: #776392
  - Add new build dependency vim-common.
* Replace screen dependency with tmux.
* Create apt-dater group for session sharing.
* Add missing directories.
* Make the build reproducible.
  Closes: #789648
* Drop automake and autoconf build dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *   Thomas Liske <liske@ibh.de>
5
5
 *
6
6
 * Copyright Holder:
7
 
 *   2008-2014 (C) IBH IT-Service GmbH [https://www.ibh.de/apt-dater/]
 
7
 *   2008-2015 (C) IBH IT-Service GmbH [https://www.ibh.de/apt-dater/]
8
8
 *
9
9
 * License:
10
10
 *   This program is free software; you can redistribute it and/or modify
23
23
 */
24
24
 
25
25
#include <glib/gstdio.h>
 
26
#include <gio/gio.h>
26
27
 
27
28
#include "apt-dater.h"
28
29
#include "exec.h"
29
 
#include "screen.h"
 
30
#include "ttymux.h"
30
31
#include "stats.h"
31
32
#include "lock.h"
32
33
#include "autoref.h"
36
37
# include "config.h"
37
38
#endif
38
39
 
 
40
void
 
41
stats_changed(GFileMonitor     *monitor,
 
42
             GFile            *file,
 
43
             GFile            *other_file,
 
44
             GFileMonitorEvent event_type,
 
45
             gpointer          user_data) {
 
46
 
 
47
  HostNode *n = user_data;
 
48
  g_assert(n);
 
49
 
 
50
  switch(event_type) {
 
51
  case G_FILE_MONITOR_EVENT_DELETED:
 
52
    n->category = (g_file_test(n->statstmpf, G_FILE_TEST_EXISTS) ? C_REFRESH : C_UNKNOWN);
 
53
    rebuilddl = TRUE; /* Trigger a DrawList rebuild */
 
54
    ;;
 
55
  case G_FILE_MONITOR_EVENT_CREATED:
 
56
    getUpdatesFromStat(n);
 
57
    rebuilddl = TRUE; /* Trigger a DrawList rebuild */
 
58
    ;;
 
59
  default:
 
60
    return;
 
61
    ;;
 
62
  }
 
63
}
 
64
 
 
65
void stats_initialize(HostNode *n) {
 
66
  GFile *path = g_file_new_for_path(n->statsfile);
 
67
  n->mon_stats = g_file_monitor(path, G_FILE_MONITOR_SEND_MOVED, NULL, NULL);
 
68
  g_object_unref(path);
 
69
 
 
70
  g_signal_connect(n->mon_stats, "changed", G_CALLBACK(stats_changed), n);
 
71
}
 
72
 
 
73
 
39
74
gchar *getStatsFile(const HostNode *n)
40
75
{
41
76
 if(g_file_test(n->statsfile, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS) == FALSE)
47
82
gboolean prepareStatsFile(HostNode *n)
48
83
{
49
84
 g_unlink(n->statsfile);
50
 
 
51
 
 n->fpstat = fopen(n->statsfile, "wx");
 
85
 g_unlink(n->statstmpf);
 
86
 n->fpstat = fopen(n->statstmpf, "wx");
52
87
 
53
88
 return n->fpstat != NULL;
54
89
}
55
90
 
56
91
 
57
 
void refreshStatsOfNode(gpointer n)
 
92
void refreshStatsOfNode(gpointer p)
58
93
{
59
 
 if( ((HostNode *)n)->fpstat ) {
60
 
    fclose(((HostNode *)n)->fpstat);
61
 
    ((HostNode *)n)->fpstat = NULL;
62
 
 }
63
 
 
64
 
 getUpdatesFromStat(((HostNode *) n));
65
 
 
66
 
 unsetLockForHost((HostNode *) n);
67
 
 
68
 
 rebuilddl = TRUE; /* Trigger a DrawList rebuild */
 
94
  HostNode *n = (HostNode *)p;
 
95
  if(n->fpstat ) {
 
96
    fclose(n->fpstat);
 
97
    n->fpstat = NULL;
 
98
 
 
99
    g_rename(n->statstmpf, n->statsfile);
 
100
  }
 
101
 
 
102
  /* getUpdatesFromStat(n);*/
 
103
  unsetLockForHost(n);
 
104
 
 
105
  //  rebuilddl = TRUE; /* Trigger a DrawList rebuild */
69
106
}
70
107
 
71
108
 
170
207
 
171
208
 if(!n) return (FALSE);
172
209
 
173
 
 if(!getStatsFile(n)) {
174
 
  n->category = C_UNKNOWN;
175
 
  return (TRUE);
176
 
 }
177
 
 
178
210
#ifdef FEAT_AUTOREF
179
211
 struct stat sbuf;
180
212
 if(!stat(n->statsfile, &sbuf))
182
214
#endif
183
215
 
184
216
 if(!(fp = (FILE *) g_fopen(n->statsfile, "r"))) {
185
 
  n->category = C_UNKNOWN;
 
217
  n->category = (g_file_test(n->statstmpf, G_FILE_TEST_EXISTS) ? C_REFRESH : C_UNKNOWN);
186
218
  return (TRUE);
187
219
 }
188
220
 
472
504
 while(ho) {
473
505
  HostNode *n = (HostNode *) ho->data;
474
506
 
475
 
  if(screen_get_sessions(n)) {
 
507
  if(TTYMUX_GET_SESSIONS(n)) {
476
508
   if(n->category != C_SESSIONS) {
477
509
    n->category = C_SESSIONS;
478
510
    rebuilddl = TRUE;