aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libconfig-ruby/Rakefile
blob: 62dc34d43d87ba430c6cca4e72ed0611ac7ec70a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require 'rubygems'
require 'rake/gempackagetask'

spec = Gem::Specification.new do |s| 
  s.name = "rconfig"
  s.version = "1.0"
  s.author = "Peter Zotov"
  s.email = "whitequark@whitequark.ru"
  s.platform = Gem::Platform::RUBY
  s.summary = "libconfig bindings"
  s.files = [ File.join('ext', 'extconf.rb'), File.join('ext', 'rconfig.c') ].to_a
  s.extensions = 'ext/extconf.rb'
end
 
Rake::GemPackageTask.new(spec) do |pkg| 
end
 
ss='deletions'>-0/+1 2014-12-28New Upstream Snapshot (commit b46a22c)Jonathan McCrohan1-0/+6 2014-12-28Imported Upstream version 0+git20141218.b46a22cupstream/0+git20141218.b46a22cJonathan McCrohan535-639/+317 2014-10-20Release 0+git20141009.d26b627-1debian/0+git20141009.d26b627-1Jonathan McCrohan1-2/+2 2014-10-20Fix up packaging to account for move to DVBv5Jonathan McCrohan2-2/+6 2014-10-20delete d/dtv-scan-files.install; Upstream now supplies a MakefileJonathan McCrohan2-4/+1 2014-10-15d/control: update Standards Version to 3.9.6Jonathan McCrohan2-1/+3 2014-10-15d/control: add Build-Depends on dvb-toolsJonathan McCrohan2-1/+2 2014-10-15New Upstream Snapshot (commit d26b627)Jonathan McCrohan1-0/+10 2014-10-15Imported Upstream version 0+git20141009.d26b627upstream/0+git20141009.d26b627Jonathan McCrohan2010-11120/+159271 2014-07-23Release 0+git20140611.14bd6c7-1debian/0+git20140611.14bd6c7-1Jonathan McCrohan1-2/+2 2014-07-23New Upstream Snapshot (commit 14bd6c7)Jonathan McCrohan1-2/+3 2014-07-23Imported Upstream version 0+git20140611.14bd6c7upstream/0+git20140611.14bd6c7Jonathan McCrohan7-11/+60 2014-05-13New Upstream Snapshot (commit 1246b27)Jonathan McCrohan1-0/+6 2014-05-13Imported Upstream version 0+git20140512.1246b27upstream/0+git20140512.1246b27Jonathan McCrohan391-301/+3983 2014-04-05Release 0+git20140326.cfc2975-1debian/0+git20140326.cfc2975-1Jonathan McCrohan1-2/+2 2014-04-05d/control: update Homepage (upstream has moved from Gitweb to cgit)Jonathan McCrohan2-1/+2 2014-04-05New Upstream Snapshot (commit cfc2975)Jonathan McCrohan1-0/+6 2014-04-05Imported Upstream version 0+git20140326.cfc2975upstream/0+git20140326.cfc2975Jonathan McCrohan118-656/+877 2014-01-16Release 0+git20140107.1850cf8-1debian/0+git20140107.1850cf8-1Jonathan McCrohan1-2/+2 2014-01-16Update Standards Version to 3.9.5Jonathan McCrohan2-1/+9 ed short CRC(const char *s) { int i; unsigned short crc; /* seed value */ crc = 0xffff; while (*s != '\0') { crc ^= *s++; for (i = 0; i < 8; i++) crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY : 0); } return crc; } static void exec_thread(void *data) { EXEC_THREAD *Thread = (EXEC_THREAD *) data; FILE *pipe; char buffer[SHM_SIZE]; int len; /* use a safe path */ putenv("PATH=/usr/local/bin:/usr/bin:/bin"); /* forever... */ while (1) { pipe = popen(Thread->cmd, "r"); if (pipe == NULL) { error("exec error: could not run pipe '%s': %s", Thread->cmd, strerror(errno)); len = 0; } else { len = fread(buffer, 1, SHM_SIZE - 1, pipe); if (len <= 0) { error("exec error: could not read from pipe '%s': %s", Thread->cmd, strerror(errno)); len = 0; } pclose(pipe); } /* force trailing zero */ buffer[len] = '\0'; /* remove trailing CR/LF */ while (len > 0 && (buffer[len - 1] == '\n' || buffer[len - 1] == '\r')) { buffer[--len] = '\0'; } /* lock shared memory */ mutex_lock(Thread->mutex); /* write data */ strncpy(Thread->ret, buffer, SHM_SIZE); /* unlock shared memory */ mutex_unlock(Thread->mutex); usleep(Thread->delay); } } static void destroy_exec_thread(const int n) { thread_destroy(Thread[n].pid); if (Thread[n].mutex != 0) mutex_destroy(Thread[n].mutex); if (Thread[n].cmd) free(Thread[n].cmd); if (Thread[n].key) free(Thread[n].key); if (Thread[n].ret) shm_destroy(Thread[n].shmid, Thread[n].ret); Thread[n].delay = 0; Thread[n].mutex = 0; Thread[n].pid = 0; Thread[n].shmid = 0; Thread[n].cmd = NULL; Thread[n].key = NULL; Thread[n].ret = NULL; } static int create_exec_thread(const char *cmd, const char *key, const int delay) { char name[10]; if (max_thread >= NUM_THREADS) { error("cannot create exec thread <%s>: thread buffer full!", cmd); return -1; } max_thread++; Thread[max_thread].delay = delay; Thread[max_thread].mutex = mutex_create(); Thread[max_thread].pid = -1; Thread[max_thread].cmd = strdup(cmd); Thread[max_thread].key = strdup(key); Thread[max_thread].ret = NULL; /* create communication buffer */ Thread[max_thread].shmid = shm_create((void **) &Thread[max_thread].ret, SHM_SIZE); /* catch error */ if (Thread[max_thread].shmid < 0) { error("cannot create exec thread <%s>: shared memory allocation failed!", cmd); destroy_exec_thread(max_thread--); return -1; } /* create thread */ qprintf(name, sizeof(name), "exec-%s", key); Thread[max_thread].pid = thread_create(name, exec_thread, &Thread[max_thread]); /* catch error */ if (Thread[max_thread].pid < 0) { error("cannot create exec thread <%s>: fork failed?!", cmd); destroy_exec_thread(max_thread--); return -1; } return 0; } static int do_exec(const char *cmd, const char *key, int delay) { int i, age; age = hash_age(&EXEC, key); if (age < 0) { hash_put(&EXEC, key, ""); /* first-time call: create thread */ if (delay < 10) { error("exec(%s): delay %d is too short! using 10 msec", cmd, delay); delay = 10; } if (create_exec_thread(cmd, key, 1000 * delay)) { return -1; } return 0; } /* reread every 10 msec only */ if (age > 0 && age <= 10) return 0; /* find thread */ for (i = 0; i <= max_thread; i++) { if (strcmp(key, Thread[i].key) == 0) { /* lock shared memory */ mutex_lock(Thread[i].mutex); /* copy data */ hash_put(&EXEC, key, Thread[i].ret); /* unlock shared memory */ mutex_unlock(Thread[i].mutex); return 0; } } error("internal error: could not find thread exec-%s", key); return -1; } static void my_exec(RESULT * result, RESULT * arg1, RESULT * arg2) { char *cmd, key[5], *val; int delay; cmd = R2S(arg1); delay = (int) R2N(arg2); qprintf(key, sizeof(key), "%x", CRC(cmd)); if (do_exec(cmd, key, delay) < 0) { SetResult(&result, R_STRING, ""); return; } val = hash_get(&EXEC, key, NULL); if (val == NULL) val = ""; SetResult(&result, R_STRING, val); } int plugin_init_exec(void) { hash_create(&EXEC); AddFunction("exec", 2, my_exec); return 0; } void plugin_exit_exec(void) { int i; for (i = 0; i <= max_thread; i++) { destroy_exec_thread(i); } hash_destroy(&EXEC); }