~ubuntu-branches/ubuntu/saucy/nut/saucy

« back to all changes in this revision

Viewing changes to server/sockdebug.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2005-07-20 19:48:50 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050720194850-oo61wjr33rrx2mre
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
        if (fd < 0) {
58
58
                perror("socket");
59
 
                exit(1);
 
59
                exit(EXIT_FAILURE);
60
60
        }
61
61
 
62
62
        ret = connect(fd, (struct sockaddr *) &sa, sizeof(sa));
63
63
 
64
64
        if (ret < 0) {
65
65
                perror("connect");
66
 
                exit(1);
 
66
                exit(EXIT_FAILURE);
67
67
        }
68
68
 
69
69
#if 0
71
71
 
72
72
        if (ret < 0) {
73
73
                perror("fcntl(get)");
74
 
                exit(1);
 
74
                exit(EXIT_FAILURE);
75
75
        }
76
76
 
77
77
        ret = fcntl(fd, F_SETFL, ret | O_NDELAY);
78
78
 
79
79
        if (ret < 0) {
80
80
                perror("fcntl(set)");
81
 
                exit(1);
 
81
                exit(EXIT_FAILURE);
82
82
        }
83
83
#endif
84
84
 
94
94
 
95
95
        if (ret == 0) {
96
96
                fprintf(stderr, "read on socket returned 0\n");
97
 
                exit(0);
 
97
                exit(EXIT_FAILURE);
98
98
        }
99
99
 
100
100
        if (ret < 0) {
101
101
                perror("read sockfd"); 
102
 
                exit(1);
 
102
                exit(EXIT_FAILURE);
103
103
        }
104
104
 
105
105
        for (i = 0; i < ret; i++) {
122
122
 
123
123
        if (argc != 2) {
124
124
                fprintf(stderr, "usage: %s <socket name>\n", argv[0]);
125
 
                fprintf(stderr, "       %s /var/state/ups/newapc-ttyS1.newsock\n",
 
125
                fprintf(stderr, "       %s /var/state/ups/apcsmart-ttyS1.newsock\n",
126
126
                        argv[0]);
127
 
                exit(1);
 
127
                exit(EXIT_SUCCESS);
128
128
        }
129
129
 
130
130
        sockfd = socket_connect(argv[1]);
159
159
 
160
160
                        ret = write(sockfd, buf, strlen(buf));
161
161
 
162
 
                        if (ret != strlen(buf)) {
 
162
                        if ((ret < 0) || (ret != (int) strlen(buf))) {
163
163
                                perror("write to socket");
164
 
                                exit(1);
 
164
                                exit(EXIT_FAILURE);
165
165
                        }
166
166
                }
167
167
        }
168
168
 
169
 
        return 0;
 
169
        /* NOTREACHED */
 
170
        exit(EXIT_FAILURE);
170
171
}