source: vendor/current/examples/libsmbclient/testnotify.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 1.3 KB
Line 
1#include <sys/types.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <string.h>
5#include <time.h>
6#include <errno.h>
7#include <libsmbclient.h>
8#include <inttypes.h>
9#include "get_auth_data_fn.h"
10
11static int notify_cb(const struct smbc_notify_callback_action *actions,
12 size_t num_actions, void *private_data)
13{
14 int *count = private_data;
15 size_t i;
16
17 printf("%zu\n", num_actions);
18
19 for (i=0; i<num_actions; i++) {
20 const struct smbc_notify_callback_action *a = &actions[i];
21 printf("%s: %"PRIu32"\n", a->filename, a->action);
22 }
23
24 *count -= 1;
25 if (*count < 0) {
26 return 1;
27 }
28
29 return 0;
30}
31
32int main(int argc, char * argv[])
33{
34 int fd;
35 int ret;
36 int debug = 0;
37 int saved_errno;
38 char path[2048];
39 char * p;
40 int count = 1000;
41
42 smbc_init(get_auth_data_fn, debug);
43
44 fprintf(stdout, "Path: ");
45 *path = '\0';
46 fgets(path, sizeof(path) - 1, stdin);
47 if (strlen(path) == 0) {
48 return 0;
49 }
50
51 p = path + strlen(path) - 1;
52 if (*p == '\n') {
53 *p = '\0';
54 }
55
56 fd = smbc_opendir(path);
57 if (fd < 0) {
58 perror("smbc_open");
59 return 1;
60 }
61
62 ret = smbc_notify(fd, 1,
63 SMBC_NOTIFY_CHANGE_SECURITY|
64 SMBC_NOTIFY_CHANGE_FILE_NAME,
65 1000, notify_cb, &count);
66 if (ret < 0) {
67 saved_errno = errno;
68 }
69
70 smbc_close(fd);
71
72 if (ret < 0) {
73 errno = saved_errno;
74 perror("notify");
75 }
76
77 return 0;
78}
Note: See TracBrowser for help on using the repository browser.