From 198b7f6e99952b465b40eacc6a740cbc6a9702e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Acun=CC=83a?= Date: Mon, 21 Nov 2016 12:54:31 -0300 Subject: [PATCH 1/2] Synchronous user-agent obtaining for mac and linux --- lib/system/index.js | 2 +- lib/system/linux/index.js | 18 ++++++++++++++---- lib/system/mac/index.js | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/system/index.js b/lib/system/index.js index 5496af128..4a28a43ca 100644 --- a/lib/system/index.js +++ b/lib/system/index.js @@ -25,7 +25,7 @@ var capitalize = function(str) { module.exports = system; system.os_name = os_name; system.get_os_version(function(err, os_version){ - system.user_agent = 'Prey/' + version + ' (Node ' + process.version + ' ' + system.os_name[0].toUpperCase() + system.os_name.slice(1) + ' ' + os_version + ')'; + if (!err) system.user_agent = 'Prey/' + version + ' (Node ' + process.version + ' ' + system.os_name[0].toUpperCase() + system.os_name.slice(1) + ' ' + os_version + ')'; }); system.paths = require('./paths'); diff --git a/lib/system/linux/index.js b/lib/system/linux/index.js index c68f3c256..3ebec7dbc 100644 --- a/lib/system/linux/index.js +++ b/lib/system/linux/index.js @@ -7,13 +7,23 @@ // GPLv3 Licensed ////////////////////////////////////////// -var release = require('os').release, - exec = require('child_process').exec, - distro = require('linus'); +var cp = require('child_process'), + release = require('os').release, + distro = require('linus'), + exec = cp.exec, + execSync = cp.execSync; exports.get_os_name = distro.name; -exports.get_os_version = distro.version; +exports.get_os_version = function(callback) { + var stdout; + try { + stdout = execSync('lsb_release -rs'); + } catch (e) { + return cb(new Error("Couldn't get OS version.")) + } + callback(null, stdout.toString().trim()); +} /** * Callsback the user logged in. diff --git a/lib/system/mac/index.js b/lib/system/mac/index.js index 27a200b0f..86cffb46f 100644 --- a/lib/system/mac/index.js +++ b/lib/system/mac/index.js @@ -5,9 +5,11 @@ // GPLv3 Licensed ////////////////////////////////////////// -var exec = require('child_process').exec, - airport = require('./airport'), - os_name = process.platform.replace('darwin', 'mac'); +var cp = require('child_process'), + airport = require('./airport'), + os_name = process.platform.replace('darwin', 'mac'), + exec = cp.exec, + execSync = cp.execSync; exports.reconnect = airport.reconnect; @@ -48,9 +50,13 @@ exports.get_os_name = function(cb) { } exports.get_os_version = function(cb) { - exec('sw_vers -productVersion', function(err, stdout) { - cb(err, stdout && stdout.toString().trim()) - }) + var stdout; + try { + stdout = execSync('sw_vers -productVersion'); + } catch (e) { + return cb(new Error("Couldn't get OS version.")) + } + cb(null, stdout.toString().trim()); } exports.process_running = function(process_name, callback) { From af210ff6afec9bf97945d54c8b148c8d6f038afa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Acun=CC=83a?= Date: Tue, 22 Nov 2016 18:12:03 -0300 Subject: [PATCH 2/2] Fix get_os_version callbacks --- lib/system/linux/index.js | 10 +++++----- lib/system/mac/index.js | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/system/linux/index.js b/lib/system/linux/index.js index 3ebec7dbc..a1511084d 100644 --- a/lib/system/linux/index.js +++ b/lib/system/linux/index.js @@ -15,14 +15,14 @@ var cp = require('child_process'), exports.get_os_name = distro.name; -exports.get_os_version = function(callback) { - var stdout; +exports.get_os_version = function(cb) { + var release; try { - stdout = execSync('lsb_release -rs'); + release = execSync('lsb_release -rs'); } catch (e) { - return cb(new Error("Couldn't get OS version.")) + return cb(new Error("Unable to determine Linux OS version.")) } - callback(null, stdout.toString().trim()); + cb(null, release.toString().trim()); } /** diff --git a/lib/system/mac/index.js b/lib/system/mac/index.js index 86cffb46f..8ddf95303 100644 --- a/lib/system/mac/index.js +++ b/lib/system/mac/index.js @@ -50,13 +50,13 @@ exports.get_os_name = function(cb) { } exports.get_os_version = function(cb) { - var stdout; + var release; try { - stdout = execSync('sw_vers -productVersion'); + release = execSync('sw_vers -productVersion'); } catch (e) { - return cb(new Error("Couldn't get OS version.")) + return cb(new Error("Unable to determine Mac OS version.")) } - cb(null, stdout.toString().trim()); + cb(null, release.toString().trim()); } exports.process_running = function(process_name, callback) {