updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / logkeys / logkeys-stdout.patch
blob3f0bb793040273c1a4c75eb6bf96ce87ed8cd114
1 diff -urN logkeys-0.1.1a.org/src/logkeys.cc logkeys-0.1.1a/src/logkeys.cc
2 --- logkeys-0.1.1a.org/src/logkeys.cc 2010-05-31 07:04:57.000000000 +0200
3 +++ logkeys-0.1.1a/src/logkeys.cc 2012-01-04 13:18:49.000000000 +0100
4 @@ -237,8 +237,7 @@
5 memset(shift_keys, '\0', sizeof(shift_keys));
6 memset(altgr_keys, '\0', sizeof(altgr_keys));
8 - stdin = freopen(args.keymap, "r", stdin);
9 - if (stdin == NULL)
10 + if (freopen(args.keymap, "r", stdin) == NULL)
11 error(EXIT_FAILURE, errno, "Error opening input keymap '%s'", args.keymap);
13 unsigned int i = -1;
14 @@ -354,7 +353,9 @@
17 int main(int argc, char **argv)
18 -{
19 +{
20 + FILE *ofp;
22 on_exit(exit_cleanup, NULL);
24 if (geteuid()) error(EXIT_FAILURE, errno, "Got r00t?");
25 @@ -424,10 +425,10 @@
26 setegid(getgid());
29 - // open log file as stdout (if file doesn't exist, create it with safe 0600 permissions)
30 + // open log file (if file doesn't exist, create it with safe 0600 permissions)
31 umask(0177);
32 - stdout = freopen(args.logfile, "a", stdout);
33 - if (stdout == NULL)
34 + ofp = fopen(args.logfile, "a");
35 + if (ofp == NULL)
36 error(EXIT_FAILURE, errno, "Error opening output file '%s'", args.logfile);
38 // now we need those privileges back in order to create system-wide PID_FILE
39 @@ -457,10 +458,10 @@
40 strftime(timestamp, sizeof(timestamp), TIME_FORMAT, localtime(&cur_time));
42 if (args.flags & FLAG_NO_TIMESTAMPS)
43 - file_size += fprintf(stdout, "Logging started at %s\n\n", timestamp);
44 + file_size += fprintf(ofp, "Logging started at %s\n\n", timestamp);
45 else
46 - file_size += fprintf(stdout, "Logging started ...\n\n%s", timestamp);
47 - fflush(stdout);
48 + file_size += fprintf(ofp, "Logging started ...\n\n%s", timestamp);
49 + fflush(ofp);
51 // infinite loop: exit gracefully by receiving SIGHUP, SIGINT or SIGTERM (of which handler closes input_fd)
52 while (read(input_fd, &event, sizeof(struct input_event)) > 0) {
53 @@ -476,14 +477,14 @@
54 scan_code = event.code;
56 if (scan_code >= sizeof(char_or_func)) { // keycode out of range, log error
57 - inc_size += fprintf(stdout, "<E-%x>", scan_code);
58 + inc_size += fprintf(ofp, "<E-%x>", scan_code);
59 if (inc_size > 0) file_size += inc_size;
60 continue;
63 // if remote posting is enabled and size treshold is reached
64 if (args.post_size != 0 && file_size >= args.post_size && stat(UPLOADER_PID_FILE, &st) == -1) {
65 - fclose(stdout);
66 + fclose(ofp);
68 std::stringstream ss;
69 for (int i = 1;; ++i) {
70 @@ -496,8 +497,8 @@
71 if (rename(args.logfile, ss.str().c_str()) == -1) // move current log file to indexed
72 error(EXIT_FAILURE, errno, "Error renaming logfile");
74 - stdout = fopen(args.logfile, "a"); // open empty log file with the same name
75 - if (stdout == NULL)
76 + ofp = fopen(args.logfile, "a"); // open empty log file with the same name
77 + if (ofp == NULL)
78 error(EXIT_FAILURE, errno, "Error opening output file '%s'", args.logfile);
80 file_size = 0; // new log file is now empty
81 @@ -521,7 +522,7 @@
82 prev_code == KEY_LEFTSHIFT || prev_code == KEY_RIGHTCTRL); // if repeated key is modifier, do nothing
83 else {
84 if ((args.flags & FLAG_NO_FUNC_KEYS) && is_func_key(prev_code)); // if repeated was function key, and if we don't log function keys, then don't log repeat either
85 - else inc_size += fprintf(stdout, "<#+%d>", count_repeats);
86 + else inc_size += fprintf(ofp, "<#+%d>", count_repeats);
88 count_repeats = 0; // reset count for future use
90 @@ -533,12 +534,12 @@
91 if (scan_code == KEY_ENTER || scan_code == KEY_KPENTER ||
92 (ctrl_in_effect && (scan_code == KEY_C || scan_code == KEY_D))) {
93 if (ctrl_in_effect)
94 - inc_size += fprintf(stdout, "%lc", char_keys[to_char_keys_index(scan_code)]); // log C or D
95 + inc_size += fprintf(ofp, "%lc", char_keys[to_char_keys_index(scan_code)]); // log C or D
96 if (args.flags & FLAG_NO_TIMESTAMPS)
97 - inc_size += fprintf(stdout, "\n");
98 + inc_size += fprintf(ofp, "\n");
99 else {
100 strftime(timestamp, sizeof(timestamp), "\n" TIME_FORMAT, localtime(&event.time.tv_sec));
101 - inc_size += fprintf(stdout, "%s", timestamp); // then newline and timestamp
102 + inc_size += fprintf(ofp, "%s", timestamp); // then newline and timestamp
104 if (inc_size > 0) file_size += inc_size;
105 continue; // but don't log "<Enter>"
106 @@ -571,17 +572,17 @@
107 else // neither altgr nor shift are effective, this is a normal char
108 wch = char_keys[to_char_keys_index(scan_code)];
110 - if (wch != L'\0') inc_size += fprintf(stdout, "%lc", wch); // write character to log file
111 + if (wch != L'\0') inc_size += fprintf(ofp, "%lc", wch); // write character to log file
113 else if (is_func_key(scan_code)) {
114 if (!(args.flags & FLAG_NO_FUNC_KEYS)) { // only log function keys if --no-func-keys not requested
115 - inc_size += fprintf(stdout, "%ls", func_keys[to_func_keys_index(scan_code)]);
116 + inc_size += fprintf(ofp, "%ls", func_keys[to_func_keys_index(scan_code)]);
118 else if (scan_code == KEY_SPACE || scan_code == KEY_TAB) {
119 - inc_size += fprintf(stdout, " "); // but always log a single space for Space and Tab keys
120 + inc_size += fprintf(ofp, " "); // but always log a single space for Space and Tab keys
123 - else inc_size += fprintf(stdout, "<E-%x>", scan_code); // keycode is neither of character nor function, log error
124 + else inc_size += fprintf(ofp, "<E-%x>", scan_code); // keycode is neither of character nor function, log error
125 } // if (EV_MAKE)
127 // on key release
128 @@ -595,7 +596,7 @@
131 prev_code = scan_code;
132 - fflush(stdout);
133 + fflush(ofp);
134 if (inc_size > 0) file_size += inc_size;
136 } // while (read(input_fd))
137 @@ -603,9 +604,9 @@
138 // append final timestamp, close files and exit
139 time(&cur_time);
140 strftime(timestamp, sizeof(timestamp), "%F %T%z", localtime(&cur_time));
141 - fprintf(stdout, "\n\nLogging stopped at %s\n\n", timestamp);
142 + fprintf(ofp, "\n\nLogging stopped at %s\n\n", timestamp);
144 - fclose(stdout);
145 + fclose(ofp);
147 remove(PID_FILE);