#!/usr/bin/lua -- -- rhnop -- -- Copyright (C) 2011-2016 Christian Pointner -- -- This file is part of rhnop. -- -- rhnop is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- any later version. -- -- rhnop is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with rhnop. If not, see . -- -- -- send now and next cart# and length to nopfetchd -- this script should be called by the now/next macro cart -- the arguments should be: now# nowlen next# nextlen -- local queue_name = "/rhnop" -- reading timestamp (milliseconds since epoch) local p = assert(io.popen("/bin/date --utc '+%s %N'" , 'r')) local time = assert(p:read('*l')) p:close() local s, ns = assert(string.match(time, "([0-9]+) ([0-9]+)")) local timestamp = s .. string.format("%06d", math.floor(ns/1000)) -- check arguments if #arg < 5 then io.stderr:write("too few parameters\n") os.exit(1) end posix = require "posix" mq = require "mq" -- open message queue posix.umask("rwxrwxr-x") local q, err = mq.create(queue_name, "wo", "rw-rw----") if q == nil then q, err = mq.open(queue_name, "wo") if q == nil then io.stderr:write("creation of message queue failed: " .. err .. "\n") os.exit(1) end end -- send out message to nopfetchd local result, err = mq.send(q, timestamp .. " " .. arg[1] .. " " .. arg[2] .. " " .. arg[3] .. " " .. arg[4] .. " " .. arg[5], 0) if result == nil then io.stderr:write("sending message failed: " .. err .. "\n") os.exit(2) end mq.close(q)