Re: I have a program I wish to submit for the base

2016-02-02 Thread Janne Johansson
2016-02-01 22:31 GMT+01:00 Luke Small :

>
> I think that there is some unwritten policy that nobody can get something
> like this into the system. Why on earth hasn't this happened yet?
>
>
Yeah, I think that if anyone has something they want into base it should go
in,
even if the developers don't like it. Couldn't end in a bad way, could it?

-- 
May the most significant bit of your life be positive.


Re: I have a program I wish to submit for the base

2016-02-02 Thread Peter Hessler
On 2016 Feb 01 (Mon) at 15:31:25 -0600 (-0600), Luke Small wrote:
:I think that there is some unwritten policy that nobody can get something
:like this into the system. Why on earth hasn't this happened yet?

Your proposed addition has been rejected, and will continue to be rejected.

1) The code is not up to the quality standards of OpenBSD.

2) The feature is not desired.

3) We are not interested in "debating" this with you, please drop the subject.



Re: I have a program I wish to submit for the base

2016-02-01 Thread Luke Small
1. You can pick a mirror relatively trivially, but since I've run the
program, the fastest one isn't the one I chose manually. Also, it can
choose multiple mirrors at once, so presumably if there is a failure, it
will choose the next mirror(s) that it wrote down in pkg.conf

2. You are saying that the ftp protocol can be implemented trivially? You
are ridiculous sir.

3. How do you suggest I filter out obviously bad choices. Add on a perl
geolocation package that isn't available in a base install. How about I
just ftp download a smaller file to discover the latency.

4. How doesn't it meet standards. I wrote it according to the style man
page as far as I can tell. And I ran it through indent. Even though I think
kernel normal form is less readable.

I think that there is some unwritten policy that nobody can get something
like this into the system. Why on earth hasn't this happened yet?
On Feb 1, 2016 10:48, "Dmitrij D. Czarkoff"  wrote:

> Jorge Castillo said:
> > Why not make it a port?
>
> Making port for figuring out PKGPATH doesn't sound right.
>
> See, there are four problems with the program:
>
> 1.  It is not good enough in doing its job.  Which is funny, because
> picking right mirror is trivially done without any program.
> 2.  It uses external tools for tasks that could be trivially implemented
> in C.
> 3.  It doesn't filter out obviously bad choices, eg. users in Europe
> will test mirrors in North America.
> 4.  It doesn't meet OpenBSD's standards for code in base.
>
> Problems #2, #3 and #4 can be fixed, but problem #1 makes this
> discussion completely pointless.  Provided that all OpenBSD developers
> who cared to participate in this discussion pointed out this issue, I'd
> suggest to stop wasting time and bandwidth right here.
>
> Luke, if you disagree with my assessment, please publish your program on
> github and convince tech media to mention it.  And move to next thing.
> Thank you in advance.
>
> --
> Dmitrij D. Czarkoff
>


Re: I have a program I wish to submit for the base

2016-02-01 Thread Dmitrij D. Czarkoff
Jorge Castillo said:
> Why not make it a port? 

Making port for figuring out PKGPATH doesn't sound right.

See, there are four problems with the program:

1.  It is not good enough in doing its job.  Which is funny, because
picking right mirror is trivially done without any program.
2.  It uses external tools for tasks that could be trivially implemented
in C.
3.  It doesn't filter out obviously bad choices, eg. users in Europe
will test mirrors in North America.
4.  It doesn't meet OpenBSD's standards for code in base.

Problems #2, #3 and #4 can be fixed, but problem #1 makes this
discussion completely pointless.  Provided that all OpenBSD developers
who cared to participate in this discussion pointed out this issue, I'd
suggest to stop wasting time and bandwidth right here.

Luke, if you disagree with my assessment, please publish your program on
github and convince tech media to mention it.  And move to next thing.
Thank you in advance.

-- 
Dmitrij D. Czarkoff



Re: I have a program I wish to submit for the base

2016-02-01 Thread Stuart Henderson
On 2016/02/01 08:43, Jorge Castillo wrote:
>   the only though that has come to me concerning mirrors,
> while using OpenBSD all this years is "damn it sure would be nice to know
> which mirrors there are without connecting to the internet first".

Fixed in -current, see /etc/examples/pkg.conf.

> To anyone reading this have a nice day.

thanks :)



Re: I have a program I wish to submit for the base

2016-02-01 Thread Jorge Castillo
I can't comment on code quality since I suck at programming but you
yourself said your program does not follow style(9) as much as it could, I
think this is not a good start. Why not make it a port? If this becomes
useful to a lot of people then maybe it can be in base later, but not
before it shows to be wildly popular. To be frank a file with all available
mirrors is as good as it gets for me, I've never felt the need to see which
mirror is faster, the only though that has come to me concerning mirrors,
while using OpenBSD all this years is "damn it sure would be nice to know
which mirrors there are without connecting to the internet first". To
anyone reading this have a nice day.


Re: I have a program I wish to submit for the base

2016-01-31 Thread Luke Small
I'm not merely experimenting with kqueue because I like the shiny bells and
whistles. I want to know how fast a mirror will download the same file from
different mirrors. ftp() is shitty for expediency. It does one of three
things it fails fast, succeeds fast, or it could take FOREVERR!!! I
want to detect all three of these scenarios and stop it if it takes
forever. So I call kqueue to time how long it takes ftp to run. If it takes
too long, I kill it. I don't know of any other calls that can do this other
than kqueue. And in a fresh install with absolutely no packages, I think
the only way to do it is by using C.

-Luke

On Fri, Jan 29, 2016 at 6:44 AM, Jérémie Courrèges-Anglas 
wrote:

> Luke Small  writes:
>
> > I wanted to use kqueue. Name another script or programming language that
> > offers it from the base install. NONE!
>
> If you want to discover how to use kqueue, fine, but that's not how
> design decisions are done in OpenBSD land.
>
> > Why should I write it in another language. I already did it in C. Is
> there
> > another way other than kqueue that you can wait for the ftp call to quit,
> > while being able to kill it if it takes too long?
>
> Yes, there are other ways. There are also ways that don't involve
> ftp(1), sed(1) and uname(1).
>
> Luke, sorry if it sounds blunt but your code is just not good enough to
> be accepted into base.  You've probably learned some things when writing
> this program, and maybe it fits your use case, but that's all.
>
> Aside from that I've never felt the need for such kind of program, and
> I don't feel like there's much demand from others.
>
> Cheers,
> --
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE
>


Re: I have a program I wish to submit for the base

2016-01-31 Thread Luke Small
I fixed the uname(1) call and replaced it with uname(3) I read the style
man page. ran the program through indent.

I ran it through sed because it reduces code complexity. Why re-engineer
the wheel?

I use C because I can use kqueue from a fresh install. You have to use
unaudited packages to use perl or python kqueue. I want the program to be
safe to run as root.

I use kqueue because I like it, but also because the mirror ftp calls need
to have a wait() call that can collect the status and can enforce a timeout
period. ftp can be a bitch that runs without stopping if you let it. I'm
not willing to let it run for hours, unless the user specifically lets the
timeout period be hours, where I've written it to allow that.

-Luke

On Fri, Jan 29, 2016 at 2:19 AM, Nicholas Marriott <
nicholas.marri...@gmail.com> wrote:

> Firstly, I don't think we need this in base and I think there is little
> to no chance of it being taken, even if the code is improved.
>
> Secondly:
>
> - The code is still miles off style(9) and isn't really a consistent
>   style within itself either.
>
> - Forking uname(1)? What? No offence, but that is hilarious :-). Why
>   fork uname(1) for uname(3) but not date(1) for gettimeofday(2)?
>
> - Why would you fork sed either?
>
> I think C is the wrong tool for this. Why not write a shell, perl, or
> python script?
>
> Then if people start to use it you could make a port.
>
>
/*
 * Copyright (c) 2016 Luke N. Small
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */


/*
 * Special thanks to Dan Mclaughlin for the ftp to sed idea
 *
 * ftp -o - http://www.openbsd.org/ftp.html | \
 * sed -n \
 *  -e 's:$::' \
 * 	-e 's:	\([^<]*\)<.*:\1:p' \
 * 	-e 's:^\(	[hfr].*\):\1:p'
 */


#define EVENT_NOPOLL
#define EVENT_NOSELECT

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

struct mirror_st {
char   *country_title;
char   *mirror;
char   *install_path;
double 		diff;
struct mirror_st *next;
};

int
ftp_cmp(const void *a, const void *b)
{
struct mirror_st **one = (struct mirror_st **) a;
struct mirror_st **two = (struct mirror_st **) b;

if ((*one)->diff < (*two)->diff)
return -1;
if ((*one)->diff > (*two)->diff)
return 1;
return 0;
}

int
country_cmp(const void *a, const void *b)
{
struct mirror_st **one = (struct mirror_st **) a;
struct mirror_st **two = (struct mirror_st **) b;

//list the USA mirrors first, it will subsort correctly
int8_t temp = !strncmp("USA", (*one)->country_title, 3);
if (temp != !strncmp("USA", (*two)->country_title, 3)) {
if (temp)
return -1;
return 1;
}
return strcmp((*one)->country_title, (*two)->country_title);
}


double
get_time_diff(struct timeval a, struct timeval b)
{
long 		sec;
long 		usec;
sec = b.tv_sec - a.tv_sec;
usec = b.tv_usec - a.tv_usec;
if (usec < 0) {
--sec;
usec += 100;
}
return sec + ((double) usec / 100.0);
}

void
manpage(char *a)
{
errx(1, "%s [-s timeout] [-n maximum_mirrors_written]", a);
}


int
main(int argc, char *argv[])
{
pid_t 		ftp_pid, sed_pid;
int 		ftp_to_sed[2];
int 		sed_to_parent[2];
char 		character;
int 		i;
double 		s = 7;
int 		position , num, c, n = 5000;
FILE   *input;
struct utsname 	name;
if (uname() == -1)
err(1, NULL);

if (argc > 1) {
if (argc % 2 == 0)
manpage(argv[0]);

position = 0;
while (++position < argc) {
if (strlen(argv[position]) != 2)
manpage(argv[0]);

if (!strcmp(argv[position], "-s")) {
++position;
c = -1;
i = 0;
while ((character = argv[position][++c]) != '\0') {
if (character == '.')
++i;

if (((character < '0' || character > '9')
 && character != '.') || i > 1) {


Re: I have a program I wish to submit for the base

2016-01-31 Thread Loganaden Velvindron
On Mon, Feb 1, 2016 at 6:18 AM, Luke Small  wrote:

> I fixed the uname(1) call and replaced it with uname(3) I read the style
> man page. ran the program through indent.
>
>
2 seasoned OpenBSD developers have taken time to reply to you, and they do
not like the general idea. No seasoned OpenBSD developer has shown any
interest. I suggest you drop the discussion.


Re: I have a program I wish to submit for the base

2016-01-31 Thread Luke Small
Whoops, got rid of putting in a null character when I should have left it
in.

-Luke
/*
 * Copyright (c) 2016 Luke N. Small
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */


/*
 * Special thanks to Dan Mclaughlin for the ftp to sed idea
 *
 * ftp -o - http://www.openbsd.org/ftp.html | \
 * sed -n \
 *  -e 's:$::' \
 * 	-e 's:	\([^<]*\)<.*:\1:p' \
 * 	-e 's:^\(	[hfr].*\):\1:p'
 */


#define EVENT_NOPOLL
#define EVENT_NOSELECT

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

struct mirror_st {
char   *country_title;
char   *mirror;
char   *install_path;
double 		diff;
struct mirror_st *next;
};

int
ftp_cmp(const void *a, const void *b)
{
struct mirror_st **one = (struct mirror_st **) a;
struct mirror_st **two = (struct mirror_st **) b;

if ((*one)->diff < (*two)->diff)
return -1;
if ((*one)->diff > (*two)->diff)
return 1;
return 0;
}

int
country_cmp(const void *a, const void *b)
{
struct mirror_st **one = (struct mirror_st **) a;
struct mirror_st **two = (struct mirror_st **) b;

//list the USA mirrors first, it will subsort correctly
int8_t temp = !strncmp("USA", (*one)->country_title, 3);
if (temp != !strncmp("USA", (*two)->country_title, 3)) {
if (temp)
return -1;
return 1;
}
return strcmp((*one)->country_title, (*two)->country_title);
}


double
get_time_diff(struct timeval a, struct timeval b)
{
long 		sec;
long 		usec;
sec = b.tv_sec - a.tv_sec;
usec = b.tv_usec - a.tv_usec;
if (usec < 0) {
--sec;
usec += 100;
}
return sec + ((double) usec / 100.0);
}

void
manpage(char *a)
{
errx(1, "%s [-s timeout] [-n maximum_mirrors_written]", a);
}


int
main(int argc, char *argv[])
{
pid_t 		ftp_pid, sed_pid;
int 		ftp_to_sed[2];
int 		sed_to_parent[2];
char 		character;
int 		i;
double 		s = 7;
int 		position , num, c, n = 5000;
FILE   *input;
struct utsname 	name;
if (uname() == -1)
err(1, NULL);

if (argc > 1) {
if (argc % 2 == 0)
manpage(argv[0]);

position = 0;
while (++position < argc) {
if (strlen(argv[position]) != 2)
manpage(argv[0]);

if (!strcmp(argv[position], "-s")) {
++position;
c = -1;
i = 0;
while ((character = argv[position][++c]) != '\0') {
if (character == '.')
++i;

if (((character < '0' || character > '9')
 && character != '.') || i > 1) {

if (character == '-')
errx(1, "No negative numbers.");
errx(1, "Incorrect floating point format.");
}
}
errno = 0;
strtod(argv[position], NULL);
if (errno == ERANGE)
err(1, NULL);
if ((s = strtod(argv[position], NULL)) > 1.0)
errx(1, "-s should less than or equal to 1");
} else if (!strcmp(argv[position], "-n")) {
++position;
if (strlen(argv[position]) > 3)
errx(1, "Integer should be <= 3 digits long.");
c = -1;
n = 0;
while ((character = argv[position][++c]) != '\0') {
if (character < '0' || character > '9') {
if (character == '.')
errx(1, "No decimal points.");
if (character == '-')
errx(1, "No negative numbers.");
errx(1, "Incorrect integer format.");
}
n = n * 10 + (int) (character - '0');
   

Re: I have a program I wish to submit for the base

2016-01-29 Thread Nicholas Marriott
Firstly, I don't think we need this in base and I think there is little
to no chance of it being taken, even if the code is improved.

Secondly:

- The code is still miles off style(9) and isn't really a consistent
  style within itself either.

- Forking uname(1)? What? No offence, but that is hilarious :-). Why
  fork uname(1) for uname(3) but not date(1) for gettimeofday(2)?

- Why would you fork sed either?

I think C is the wrong tool for this. Why not write a shell, perl, or
python script?

Then if people start to use it you could make a port.



On Fri, Jan 29, 2016 at 01:34:30AM -0600, Luke Small wrote:
> I think I fixed all your suggestions. I don't strictly adhere to kernel
> normal in the use of comments and I parse command-line arguments without
> using getopt(3), but the method is robust.
> 
> -Luke
> 
>  
>  o I definitely don't think camel case will be accepted
> 
>  o I'm pretty sure strtonum(3) is strongly preferred over strtod(3) et al.

> /*
>  * Copyright (c) 2016 Luke N. Small
>  *
>  * Permission to use, copy, modify, and distribute this software for any
>  * purpose with or without fee is hereby granted, provided that the above
>  * copyright notice and this permission notice appear in all copies.
>  *
>  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
>  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
>  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
>  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
>  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
>  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
>  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>  */
>  
> 
> /* Special thanks to Dan Mclaughlin for the ftp to sed idea
>  * 
>  * ftp -o - http://www.openbsd.org/ftp.html | \
>  * sed -n \
>  *  -e 's:$::' \
>  *-e 's:  \([^<]*\)<.*:\1:p' \
>  *-e 's:^\(   [hfr].*\):\1:p'
>  */
>  
>  
> #define EVENT_NOPOLL
> #define EVENT_NOSELECT
> 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
> 
> struct mirror_st
> {
>   char * country_title;
>   char * mirror;
>   char * install_path;
>   double diff;
>   struct mirror_st * next;
> };
> 
> int ftp_cmp (const void * a, const void * b)
> {
>   struct mirror_st ** one = (struct mirror_st **)a;
>   struct mirror_st ** two = (struct mirror_st **)b;
> 
>   if ( (*one)->diff < (*two)->diff )
>   return -1;
>   if ( (*one)->diff > (*two)->diff )
>   return 1;
>   return 0;
> }
> 
> int country_cmp (const void * a, const void * b)
> {
>   struct mirror_st ** one = (struct mirror_st **)a;
>   struct mirror_st ** two = (struct mirror_st **)b;
>   
>   // list the USA mirrors first, it will subsort correctly
>   int8_t temp = !strncmp("USA", (*one)->country_title, 3);
>   if (temp != !strncmp("USA", (*two)->country_title, 3))
>   {
>   if (temp)
>   return -1;
>   return 1;
>   }
> 
>   return strcmp( (*one)->country_title, (*two)->country_title ) ;
> }
> 
> 
> double get_time_diff(struct timeval a, struct timeval b)
> {
> long sec;
> long usec;
> sec = b.tv_sec - a.tv_sec;
> usec = b.tv_usec - a.tv_usec;
> if (usec < 0)
> {
>   --sec;
>   usec += 100;
> }
> return sec + ((double)usec / 100.0);
> }
> 
> void manpage(char * a)
> {
>   errx(1, "%s [-s timeout] [-n maximum_mirrors_written]", a);
> }
> 
> 
> int main(int argc, char *argv[])
> {
>   pid_t ftp_pid, sed_pid, uname_pid;
>   int ftp_to_sed[2];
>   int sed_to_parent[2];
>   int uname_to_parent[2];
>   char uname_r[5], uname_m[20], character;
>   int i;
>   double s = 7;
>   int position, num, c, n = 5000;
>   FILE *input;
> 
>   if (argc > 1)
>   {
>   if (argc % 2 == 0)
>   manpage(argv[0]);
>   
>   position = 0;
>   while (++position < argc)
>   {
>   if (strlen(argv[position]) != 2)
>   manpage(argv[0]);
>   
>   if (!strcmp(argv[position], "-s"))
>   {
>   ++position;
>   c = -1;
>   i = 0;
>   while ((character = argv[position][++c]) != 
> '\0')
>   {
>   if (character == '.')
>   ++i;
>   
>   if ( ((character < '0' || character > 
> '9') && character != '.') || i > 1 )
>   {
>   

Re: I have a program I wish to submit for the base

2016-01-29 Thread Loganaden Velvindron
On Fri, Jan 29, 2016 at 12:44 PM, Jérémie Courrèges-Anglas 
wrote:

> Luke Small  writes:
>
> > I wanted to use kqueue. Name another script or programming language that
> > offers it from the base install. NONE!
>
>
>
Hi Luke,

I understand your perspective. If you use OpenBSD already, then I would
suggest you start by fixing bugs in documentation as you encounter them or
small fixes, as a start.

Look at what OpenBSD is currently heading: tame, improvements to OpenBGPd,
and the crazy W^X stuff.

(url: http://www.openbsd.org/papers/).

If you are looking to work for something interesting, here is a good start.
Run -current, and if you encounter a bug, try fixing it, and think about
ways to improve your small fixes.


Re: I have a program I wish to submit for the base

2016-01-29 Thread Jérémie Courrèges-Anglas
Luke Small  writes:

> I wanted to use kqueue. Name another script or programming language that
> offers it from the base install. NONE!

If you want to discover how to use kqueue, fine, but that's not how
design decisions are done in OpenBSD land.

> Why should I write it in another language. I already did it in C. Is there
> another way other than kqueue that you can wait for the ftp call to quit,
> while being able to kill it if it takes too long?

Yes, there are other ways. There are also ways that don't involve
ftp(1), sed(1) and uname(1).

Luke, sorry if it sounds blunt but your code is just not good enough to
be accepted into base.  You've probably learned some things when writing
this program, and maybe it fits your use case, but that's all.

Aside from that I've never felt the need for such kind of program, and
I don't feel like there's much demand from others.

Cheers,
-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE



Re: I have a program I wish to submit for the base

2016-01-29 Thread Luke Small
I wanted to use kqueue. Name another script or programming language that
offers it from the base install. NONE!

Why should I write it in another language. I already did it in C. Is there
another way other than kqueue that you can wait for the ftp call to quit,
while being able to kill it if it takes too long?

-Luke

On Fri, Jan 29, 2016 at 3:42 AM,  wrote:

> Fri, 29 Jan 2016 08:19:14 + Nicholas Marriott
> > Firstly, I don't think we need this in base and I think there is little
> > to no chance of it being taken, even if the code is improved.
>
> Many folks tried this part (advising Luke), he takes none and keeps
> repeating wrong concepts, his assignment looks misaligned somewhat.
>
> > Secondly:
> >
> > - The code is still miles off style(9) and isn't really a consistent
> >   style within itself either.
>
> This comes from an apprentice wannabe, probably best to recommend him
> further self help.
>
> > - Forking uname(1)? What? No offence, but that is hilarious :-). Why
> >   fork uname(1) for uname(3) but not date(1) for gettimeofday(2)?
>
> The kid knows nothing of UNIX, ask him book reading comprehension
> questions in private please.
>
> > - Why would you fork sed either?
>
> Hint: suggest another list@
>
> > I think C is the wrong tool for this. Why not write a shell, perl, or
> > python script?
>
> C is the wrong tool for that person, knows nothing of shell too.  So
> best pick learning shell first.  Typical, but never hopeless (still)?
>
> > Then if people start to use it you could make a port.
>
> Without thought at design stage, barely usable for private learning
> projects homework.  The result is reiterations on misc@ where ideas
> spark in developer heads after some kid starts asking noisily without
> listening or prior knowledge.
>


Re: I have a program I wish to submit for the base

2016-01-29 Thread Peter J. Philipp
Luke, don't feel bad.  Very little code that is "offered" gets taken by
the OpenBSD project.  OpenBSD really only takes when they see benefit
for the project.  An example for that is openssh.  What you really want
to do is focus on your own projects and make them available somewhere so
that when OpenBSD gets wind of it they'll take it.

Cheers,

-peter

On 01/29/16 09:19, Nicholas Marriott wrote:
> Firstly, I don't think we need this in base and I think there is little
> to no chance of it being taken, even if the code is improved.
>
> Secondly:
>
> - The code is still miles off style(9) and isn't really a consistent
>   style within itself either.
>
> - Forking uname(1)? What? No offence, but that is hilarious :-). Why
>   fork uname(1) for uname(3) but not date(1) for gettimeofday(2)?
>
> - Why would you fork sed either?
>
> I think C is the wrong tool for this. Why not write a shell, perl, or
> python script?
>
> Then if people start to use it you could make a port.
>
>
>
> On Fri, Jan 29, 2016 at 01:34:30AM -0600, Luke Small wrote:
>> I think I fixed all your suggestions. I don't strictly adhere to kernel
>> normal in the use of comments and I parse command-line arguments without
>> using getopt(3), but the method is robust.
>>
>> -Luke
>>
>> >
>>  o I definitely don't think camel case will be accepted
>>
>>  o I'm pretty sure strtonum(3) is strongly preferred over strtod(3) et al.
>>



Re: I have a program I wish to submit for the base

2016-01-28 Thread Luke Small
I think I fixed all your suggestions. I don't strictly adhere to kernel
normal in the use of comments and I parse command-line arguments without
using getopt(3), but the method is robust.

-Luke

/*
 * Copyright (c) 2016 Luke N. Small
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
 

/* Special thanks to Dan Mclaughlin for the ftp to sed idea
 * 
 * ftp -o - http://www.openbsd.org/ftp.html | \
 * sed -n \
 *  -e 's:$::' \
 * 	-e 's:	\([^<]*\)<.*:\1:p' \
 * 	-e 's:^\(	[hfr].*\):\1:p'
 */
 
 
#define EVENT_NOPOLL
#define EVENT_NOSELECT

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

struct mirror_st
{
	char * country_title;
	char * mirror;
	char * install_path;
	double diff;
	struct mirror_st * next;
};

int ftp_cmp (const void * a, const void * b)
{
	struct mirror_st ** one = (struct mirror_st **)a;
	struct mirror_st ** two = (struct mirror_st **)b;

	if ( (*one)->diff < (*two)->diff )
		return -1;
	if ( (*one)->diff > (*two)->diff )
		return 1;
	return 0;
}

int country_cmp (const void * a, const void * b)
{
	struct mirror_st ** one = (struct mirror_st **)a;
	struct mirror_st ** two = (struct mirror_st **)b;
	
	// list the USA mirrors first, it will subsort correctly
	int8_t temp = !strncmp("USA", (*one)->country_title, 3);
	if (temp != !strncmp("USA", (*two)->country_title, 3))
	{
		if (temp)
			return -1;
		return 1;
	}

	return strcmp( (*one)->country_title, (*two)->country_title ) ;
}


double get_time_diff(struct timeval a, struct timeval b)
{
long sec;
long usec;
sec = b.tv_sec - a.tv_sec;
usec = b.tv_usec - a.tv_usec;
if (usec < 0)
{
		--sec;
		usec += 100;
}
return sec + ((double)usec / 100.0);
}

void manpage(char * a)
{
	errx(1, "%s [-s timeout] [-n maximum_mirrors_written]", a);
}


int main(int argc, char *argv[])
{
	pid_t ftp_pid, sed_pid, uname_pid;
	int ftp_to_sed[2];
	int sed_to_parent[2];
	int uname_to_parent[2];
	char uname_r[5], uname_m[20], character;
	int i;
	double s = 7;
	int position, num, c, n = 5000;
	FILE *input;

	if (argc > 1)
	{
		if (argc % 2 == 0)
			manpage(argv[0]);
		
		position = 0;
		while (++position < argc)
		{
			if (strlen(argv[position]) != 2)
manpage(argv[0]);
			
			if (!strcmp(argv[position], "-s"))
			{
++position;
c = -1;
i = 0;
while ((character = argv[position][++c]) != '\0')
{
	if (character == '.')
		++i;
	
	if ( ((character < '0' || character > '9') && character != '.') || i > 1 )
	{
		if (character == '-')
			errx(1, "No negative numbers.");
		errx(1, "Incorrect floating point format.");
	}
}
errno = 0;
strtod(argv[position], NULL);
if (errno == ERANGE)
	err(1, NULL);
if ((s = strtod(argv[position], NULL)) > 1.0)
	errx(1, "The argument should less than or equal to 1");
			}
			else if (!strcmp(argv[position], "-n"))
			{
++position;
if (strlen(argv[position]) > 3)
	errx(1, "Integer should be less than or equal to 3 digits long.");
c = -1;
n = 0;
while ((character = argv[position][++c]) != '\0')
{
	if ( character < '0' || character > '9' )
	{
		if (character == '.')
			errx(1, "No decimal points.");
		if (character == '-')
			errx(1, "No negative numbers.");
		errx(1, "Incorrect integer format.");
	}
	n = n * 10 + (int)(character - '0');
}
			}
			else
manpage(argv[0]);
		}
	}

	struct kevent ke[1];
	struct timespec timeout;
	
	timeout.tv_sec = (int)s;
	timeout.tv_nsec = (int)(   (s - (double)timeout.tv_sec) * 10  );

	int kq = kqueue();
	if (kq == -1)
		errx(1, "kq!");

	if (pipe(uname_to_parent) == -1)
		err(1, NULL);
	

	// "uname -rm" returns version and architecture like: "5.8 amd64\n" to standard out
	uname_pid = fork();
	if (uname_pid == (pid_t) 0)
	{			/* uname child */
		close(uname_to_parent[0]);
		dup2(uname_to_parent[1], STDOUT_FILENO); /*attaching to pipe(s)*/
		execl("/usr/bin/uname","/usr/bin/uname", "-rm", NULL);
errx(1, "uname execl() failed.");
	}
	if (uname_pid == -1)
		err(1, NULL);
	
	close(uname_to_parent[1]);


	EV_SET(ke, uname_to_parent[0], EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, NULL);
	if (kevent(kq, ke, 1, NULL, 0, NULL) == -1)
	{
		kill(uname_pid, SIGKILL);
		errx(1, 

I have a program I wish to submit for the base

2016-01-28 Thread Luke Small
pkg_ping  [-s timeout]
[-n maximum_mirrors_written]

It scrapes each mirror's location and URL from  openbsd.org/ftp.html and
tests the package repository with the  version and architecture of the
machine. It kills the ftp() and sed() functions it calls from C if it takes
too long by using kqueue. It calls uname as well and I put kqueue on it
too, in case there is a chance uname can be called and stall like ftp.

After install, it can write download mirrors to /etc/pkg.conf. I want to
enable the user to write down one or many mirrors as has been calculated by
timing the download of the nearly 700 KB SHA256 file from each mirror.

I think that if pkg_add can't find a suitable mirror, pkg_ping could be
called to find the fastest available mirror(s), especially if their mirror
of choice goes down, or they put off upgrading so long that their mirror of
choice deletes their system's repository.

I think I'm done with it. It is absolutely a coincidence that it is 666
lines. I'm not changing it.

-Luke N Small
/*
 * Copyright (c) 2016 Luke N. Small
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
 

/* Special thanks to Dan Mclaughlin for the ftp to sed idea
 * 
 * ftp -o - http://www.openbsd.org/ftp.html | \
 * sed -n \
 *  -e 's:$::' \
 * 	-e 's:	\([^<]*\)<.*:\1:p' \
 * 	-e 's:^\(	[hfr].*\):\1:p'
 */
 
 
#define EVENT_NOPOLL
#define EVENT_NOSELECT

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

struct mirror_st
{
	char * countryTitle;
	char * mirror;
	char * installPath;
	double diff;
	struct mirror_st * next;
};

int ftp_cmp (const void * a, const void * b)
{
	struct mirror_st ** one = (struct mirror_st **)a;
	struct mirror_st ** two = (struct mirror_st **)b;

	if( (*one)->diff < (*two)->diff )
		return -1;
	if( (*one)->diff > (*two)->diff )
		return 1;
	return 0;
}

int country_cmp (const void * a, const void * b)
{
	struct mirror_st ** one = (struct mirror_st **)a;
	struct mirror_st ** two = (struct mirror_st **)b;
	
	// list the USA mirrors first, it will subsort correctly
	int8_t temp = !strncmp("USA", (*one)->countryTitle, 3);
	if(temp != !strncmp("USA", (*two)->countryTitle, 3))
	{
		if(temp)
			return -1;
		return 1;
	}

	return strcmp( (*one)->countryTitle, (*two)->countryTitle ) ;
}


double getTimeDiff(struct timeval a, struct timeval b)
{
long sec;
long usec;
sec = b.tv_sec - a.tv_sec;
usec = b.tv_usec - a.tv_usec;
if (usec < 0)
{
		--sec;
		usec += 100;
}
return sec + ((double)usec / 100.0);
}

void manpage(char * a)
{
	errx(1, "%s [-s timeout] [-n maximum_mirrors_written]", a);
}


int main(int argc, char *argv[])
{
	pid_t ftpPid, sedPid, unamePid;
	int ftpToSed[2];
	int sedToParent[2];
	int unameToParent[2];
	char unameR[5], unameM[20], Char;
	int i;
	double S = 7;
	int position, num, c, N = 5000;
	FILE *input;

	if(argc > 1)
	{
		if(argc % 2 == 0)
			manpage(argv[0]);
		
		position = 0;
		while(++position < argc)
		{
			if(strlen(argv[position]) != 2)
manpage(argv[0]);
			
			if(!strcmp(argv[position], "-s"))
			{
++position;
c = -1;
i = 0;
while((Char = argv[position][++c]) != '\0')
{
	if(Char == '.')
		++i;
	
	if( ((Char < '0' || Char > '9') && Char != '.') || i > 1 )
	{
		if(Char == '-')
			errx(1, "No negative numbers.");
		errx(1, "Incorrect floating point format.");
	}
}
errno = 0;
strtod(argv[position], NULL);
if(errno == ERANGE)
	err(1, NULL);
if((S = strtod(argv[position], NULL)) > 1.0)
	errx(1, "The argument should less than or equal to 1");
			}
			else if(!strcmp(argv[position], "-n"))
			{
++position;
if(strlen(argv[position]) > 3)
	errx(1, "Integer should be less than or equal to 3 digits long.");
c = -1;
N = 0;
while((Char = argv[position][++c]) != '\0')
{
	if( Char < '0' || Char > '9' )
	{
		if(Char == '.')
			errx(1, "No decimal points.");
		if(Char == '-')
			errx(1, "No negative numbers.");
		errx(1, "Incorrect integer format.");
	}
	N = N * 10 + (int)(Char - '0');
}
			}
			else
manpage(argv[0]);
		}
	}

	struct kevent ke[2];
	struct timespec timeout;
	
	timeout.tv_sec = (int)S;
	timeout.tv_nsec = (int)(   (S - (double)timeout.tv_sec) *