diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2012-11-05 21:40:19 +0100 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2012-11-05 21:40:19 +0100 |
commit | d78c869cffcae8f52ccfd6ceb4e67d8a99d6e1b3 (patch) | |
tree | 22d713b598b93217b56add13cb0db5ce10519a16 /src | |
parent | a08fc61ea352255579cbbbf22429689beaee8951 (diff) | |
download | strongswan-d78c869cffcae8f52ccfd6ceb4e67d8a99d6e1b3.tar.bz2 strongswan-d78c869cffcae8f52ccfd6ceb4e67d8a99d6e1b3.tar.xz |
eliminate deinstalled packages
Diffstat (limited to 'src')
-rw-r--r-- | src/libimcv/os_info/os_info.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/libimcv/os_info/os_info.c b/src/libimcv/os_info/os_info.c index 4f2a15dc5..110c60ea1 100644 --- a/src/libimcv/os_info/os_info.c +++ b/src/libimcv/os_info/os_info.c @@ -220,7 +220,7 @@ typedef struct { /** * line buffer */ - char line[512]; + u_char line[512]; } package_enumerator_t; @@ -239,36 +239,53 @@ static void package_enumerator_destroy(package_enumerator_t *this) static bool package_enumerator_enumerate(package_enumerator_t *this, ...) { chunk_t *name, *version; - char *pos; + u_char *pos; va_list args; - if (!fgets(this->line, sizeof(this->line), this->file)) + while (TRUE) { - return FALSE; - } - va_start(args, this); + if (!fgets(this->line, sizeof(this->line), this->file)) + { + return FALSE; + } - name = va_arg(args, chunk_t*); - name->ptr = this->line; - pos = strchr(this->line, '\t'); - if (!pos) - { - return FALSE; - } - name->len = pos++ - this->line; + pos = strchr(this->line, '\t'); + if (!pos) + { + return FALSE; + } + *pos++ = '\0'; - version = va_arg(args, chunk_t*); - version->ptr = pos; - version->len = strlen(pos) - 1; + if (!streq(this->line, "install ok installed")) + { + continue; + } + va_start(args, this); - va_end(args); - return TRUE; + name = va_arg(args, chunk_t*); + name->ptr = pos; + pos = strchr(pos, '\t'); + if (!pos) + { + return FALSE; + } + name->len = pos++ - name->ptr; + + version = va_arg(args, chunk_t*); + version->ptr = pos; + version->len = strlen(pos) - 1; + + va_end(args); + return TRUE; + } } METHOD(os_info_t, create_package_enumerator, enumerator_t*, private_os_info_t *this) { FILE *file; + const char command[] = "dpkg-query --show --showformat=" + "'${Status}\t${PackageSpec}\t${Version}\n'"; package_enumerator_t *enumerator; /* Only Debian and Ubuntu package enumeration is currently supported */ @@ -278,7 +295,7 @@ METHOD(os_info_t, create_package_enumerator, enumerator_t*, } /* Open a pipe stream for reading the output of the dpkg-query commmand */ - file = popen("/usr/bin/dpkg-query --show", "r"); + file = popen(command, "r"); if (!file) { DBG1(DBG_IMC, "failed to run dpkg command"); |