This file is indexed.

/usr/share/doc/libcomedi-dev/demo/sigio.c is in libcomedi-dev 0.10.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
 * SIGIO example
 * Part of Comedilib
 *
 * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
 *
 * This file may be freely modified, distributed, and combined with
 * other software, as long as proper attribution is given in the
 * source code.
 */

#define _GNU_SOURCE

#include <stdio.h>
#include <comedilib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <ctype.h>
#include <signal.h>
#include <string.h>
#include <sys/time.h>
#include "examples.h"

comedi_t *device;


void print_time(void);

void sigio_handler(int sig)
{
	print_time();
}

void print_time(void)
{
	struct timeval tv;
	static struct timeval oldtime={0};
	int dsec,dusec;

	gettimeofday(&tv,NULL);

	dsec=tv.tv_sec-oldtime.tv_sec;
	dusec=tv.tv_usec-oldtime.tv_usec;
	if(dusec<0){
		dsec--;
		dusec+=1000000;
	}
	printf("%d.%06d +%d.%06d\n",(int)tv.tv_sec,(int)tv.tv_usec,dsec,dusec);

	oldtime=tv;
}

int out_subd;

void config_output(void)
{
	int i;

	for(i=0;i<8;i++){
		comedi_dio_config(device,out_subd,i,COMEDI_OUTPUT);
	}
}

int count;

#define BUFSZ 1024
sampl_t buf[BUFSZ];

void do_cmd_1(comedi_t *dev, int subdevice);
void do_cmd_2(comedi_t *dev);
void do_cmd(comedi_t *dev,comedi_cmd *cmd);

int main(int argc, char *argv[])
{
	struct sigaction sa;
	int ret;
	sigset_t sigset;
	int flags;
	struct parsed_options options;

	init_parsed_options(&options);
	parse_options(&options, argc, argv);

	device = comedi_open(options.filename);
	if(!device){
		perror(options.filename);
		exit(1);
	}

	out_subd = 2;

	config_output();

	fcntl(comedi_fileno(device), F_SETOWN, getpid());
	flags = fcntl(comedi_fileno(device),F_GETFL);
	ret = fcntl(comedi_fileno(device),F_SETFL,flags|O_ASYNC);
	//ret = fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK|O_ASYNC);
	if(ret<0)perror("fcntl");

	memset(&sa,0,sizeof(sa));
	sa.sa_handler = &sigio_handler;
	ret = sigaction(SIGIO,&sa,NULL);
	if(ret<0)perror("sigaction");

	sigemptyset(&sigset);
	sigaddset(&sigset,SIGIO);
	ret = sigprocmask(SIG_UNBLOCK,&sigset,NULL);
	if(ret<0)perror("sigprocmask");

#if 0
	{
	struct sched_param p;
	memset(&p,0,sizeof(p));
	p.sched_priority = 1;
	ret = sched_setscheduler(0,SCHED_FIFO,&p);
	if(ret<0)perror("sched_setscheduler");
	}
#endif

	do_cmd_1(device, options.subdevice);

	return 0;
}

void do_cmd(comedi_t *dev,comedi_cmd *cmd)
{
	int total=0;
	int ret;
	int go;

	ret=comedi_command_test(dev,cmd);

	printf("test ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command_test");
		return;
	}

	dump_cmd(stdout,cmd);

	ret=comedi_command_test(dev,cmd);

	printf("test ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command_test");
		return;
	}

	dump_cmd(stdout,cmd);

	ret=comedi_command(dev,cmd);

	printf("ret=%d\n",ret);
	if(ret<0){
		printf("errno=%d\n",errno);
		comedi_perror("comedi_command");
		return;
	}

	go=1;
	while(go){
		ret=read(comedi_fileno(dev),buf,BUFSZ);
		if(ret<0){
			if(errno==EAGAIN){
				printf("EAGAIN\n");
				usleep(10000);
			}else{
				go = 0;
				perror("read");
			}
		}else if(ret==0){
			go = 0;
		}else{
			//int i;

			total+=ret;
			//printf("read %d %d\n",ret,total);
			//printf("count = %d\n",count);
			//print_time();
		}
	}
}

unsigned int chanlist[0];
/*
 * This part of the demo measures channels 1, 2, 3, 4 at a rate of
 * 10 khz, with the inter-sample time at 10 us (100 khz).  The number
 * of scans measured is 10.  This is analogous to the old mode2
 * acquisition.
 */
void do_cmd_1(comedi_t *dev, int subdevice)
{
	comedi_cmd cmd;

	memset(&cmd,0,sizeof(cmd));

	/* the subdevice that the command is sent to */
	cmd.subdev = subdevice;

	/* flags */
	cmd.flags =	TRIG_WAKE_EOS;

	cmd.start_src =		TRIG_NOW;
	cmd.start_arg =		0;

	cmd.scan_begin_src =	TRIG_TIMER;
	cmd.scan_begin_arg =	msec_to_nsec(100);

#if 1
	cmd.convert_src =	TRIG_TIMER;
	cmd.convert_arg =	1;
#else
	cmd.convert_src =	TRIG_ANY;
	cmd.convert_arg =	0;
#endif

	cmd.scan_end_src =	TRIG_COUNT;
	cmd.scan_end_arg =	1;

	cmd.stop_src =		TRIG_NONE;
	cmd.stop_arg =		0;

	cmd.chanlist =		chanlist;
	cmd.chanlist_len =	1;

	chanlist[0]=CR_PACK(0,0,0);

	do_cmd(dev,&cmd);
}