void free_superspec( FL_OBJECT * obj ) { SuperSPEC *ssp = obj->u_vdata; int i; if ( ! ssp ) return; for ( i = 1; i <= ssp->nlines; ++i ) { if ( ssp->content ) fl_free( ssp->content[ i ] ); if ( ssp->shortcut ) fl_free( ssp->shortcut[ i ] ); if ( ssp->callback ) fl_free( ssp->callback[ i ] ); } fl_free( ssp->misc_char ); fl_free( ssp->mode ); fl_free( ssp->mval ); fl_free( ssp->content ); fl_free( ssp->shortcut ); fl_free( ssp->callback ); }
void fl_add_signal_callback( int s, FL_SIGNAL_HANDLER cb, void * data ) { FLI_SIGNAL_REC *sig_rec, *rec = fli_context->signal_rec; if ( ! fli_handle_signal ) fli_handle_signal = handle_signal; while ( rec && rec->signum != s ) rec = rec->next; if ( rec ) { rec->callback = cb; rec->data = data; } else { sig_rec = fl_malloc( sizeof *sig_rec ); sig_rec->next = NULL; sig_rec->data = data; sig_rec->callback = cb; sig_rec->signum = s; sig_rec->caught = 0; if ( ! sig_direct ) { #if defined HAVE_SIGACTION struct sigaction sact; sact.sa_handler = default_signal_handler; sigemptyset( &sact.sa_mask ); sact.sa_flags = 0; if ( sigaction( s, &sact, &sig_rec->old_sigact ) < 0 ) #else errno = 0; sig_rec->ocallback = signal( s, default_signal_handler ); if ( sig_rec->ocallback == ( FLI_OSSIG_HANDLER ) - 1L || errno ) #endif { M_err( "fl_add_signal_callback", "Can't add handler for " "signal %d", s ); fl_free( sig_rec ); return; } } if ( fli_context->signal_rec ) sig_rec->next = fli_context->signal_rec; fli_context->signal_rec = sig_rec; } }
void yasm_free(struct yasm *y) { if (!y) return; free(y->pttfile); free(y->lstfile); free(y->binfile); fl_free(y->fl); st_free(y->st_asm); l_free(y->l); free(y); }
int fl_set_font_name_f( int n, const char * fmt, ... ) { char *buf; int ret; EXPAND_FORMAT_STRING( buf, fmt ); ret = fl_set_font_name( n, buf ); fl_free( buf ); return ret; }
void fl_set_tabstop( const char *s ) { static int set; if ( s ) { if ( set ) fl_free( *tabstop ); *tabstop = fl_strdup( s ); *tabstopNchar = strlen( *tabstop ); set = 1; } }
static void ip6_fl_purge(struct net *net) { int i; write_lock(&ip6_fl_lock); for (i = 0; i <= FL_HASH_MASK; i++) { struct ip6_flowlabel *fl, **flp; flp = &fl_ht[i]; while ((fl = *flp) != NULL) { if (fl->fl_net == net && atomic_read(&fl->users) == 0) { *flp = fl->next; fl_free(fl); atomic_dec(&fl_size); continue; } flp = &fl->next; } } write_unlock(&ip6_fl_lock); }
static void ip6_fl_gc(unsigned long dummy) { int i; unsigned long now = jiffies; unsigned long sched = 0; spin_lock(&ip6_fl_lock); for (i = 0; i <= FL_HASH_MASK; i++) { struct ip6_flowlabel *fl; struct ip6_flowlabel __rcu **flp; flp = &fl_ht[i]; while ((fl = rcu_dereference_protected(*flp, lockdep_is_held(&ip6_fl_lock))) != NULL) { if (atomic_read(&fl->users) == 0) { unsigned long ttd = fl->lastuse + fl->linger; if (time_after(ttd, fl->expires)) fl->expires = ttd; ttd = fl->expires; if (time_after_eq(now, ttd)) { *flp = fl->next; fl_free(fl); atomic_dec(&fl_size); continue; } if (!sched || time_before(ttd, sched)) sched = ttd; } flp = &fl->next; } } if (!sched && atomic_read(&fl_size)) sched = now + FL_MAX_LINGER; if (sched) { mod_timer(&ip6_fl_gc_timer, sched); } spin_unlock(&ip6_fl_lock); }
static void __net_exit ip6_fl_purge(struct net *net) { int i; spin_lock(&ip6_fl_lock); for (i = 0; i <= FL_HASH_MASK; i++) { struct ip6_flowlabel *fl, **flp; flp = &fl_ht[i]; while ((fl = rcu_dereference_protected(*flp, lockdep_is_held(&ip6_fl_lock))) != NULL) { if (net_eq(fl->fl_net, net) && atomic_read(&fl->users) == 0) { *flp = fl->next; fl_free(fl); atomic_dec(&fl_size); continue; } flp = &fl->next; } } spin_unlock(&ip6_fl_lock); }
int main(int argc, char * argv[]) { //DEFININDO SEMENTE DO RAND srand(time(NULL)); cria_processos_chamada=0; primeira_vez=1; XInitThreads(); //DEFINICOES DO FORMULARIO FD_projeto *fd_projeto; fl_initialize( &argc, argv, 0, 0, 0 ); fd_projeto = create_form_projeto(); fl_show_form( fd_projeto->projeto, FL_PLACE_CENTERFREE, FL_FULLBORDER, "Núcleo Gerenciador de Processos" ); // THREAD DO NÚCLEO pthread_attr_setscope(&T_NUCLEO_ATTR, PTHREAD_SCOPE_SYSTEM); pthread_attr_init(&T_NUCLEO_ATTR); pthread_create(&T_NUCLEO, &T_NUCLEO_ATTR, (void *) &nucleo, NULL); //LOOP DO FORMULARIO while(1) { //printf("passei antees do_forms\n"); //fflush(stdout); fl_do_forms(); sleep(1); } //pthread_join(T_ESCALONADOR, NULL); //FINALIZANDO FORMULARIO if ( fl_form_is_visible( fd_projeto->projeto ) ) fl_hide_form( fd_projeto->projeto ); fl_free( fd_projeto ); fl_finish(); return 0; }
static void ip6_fl_gc(unsigned long dummy) { int i; unsigned long now = jiffies; unsigned long sched = 0; write_lock(&ip6_fl_lock); for (i=0; i<=FL_HASH_MASK; i++) { struct ip6_flowlabel *fl, **flp; flp = &fl_ht[i]; while ((fl=*flp) != NULL) { if (atomic_read(&fl->users) == 0) { unsigned long ttd = fl->lastuse + fl->linger; if (time_after(ttd, fl->expires)) fl->expires = ttd; ttd = fl->expires; if (time_after_eq(now, ttd)) { *flp = fl->next; fl_free(fl); atomic_dec(&fl_size); continue; } if (!sched || time_before(ttd, sched)) sched = ttd; } flp = &fl->next; } } if (!sched && atomic_read(&fl_size)) sched = now + FL_MAX_LINGER; if (sched) { ip6_fl_gc_timer.expires = sched; add_timer(&ip6_fl_gc_timer); } write_unlock(&ip6_fl_lock); }
int fl_show_question( const char * str, int ans ) { FL_OBJECT *retobj; char shortcut[ 4 ]; int k = 0; if ( fd_yesno ) { fl_hide_form( fd_yesno->form ); fl_free_form( fd_yesno->form ); fl_free( fd_yesno ); } else fl_deactivate_all_forms( ); fd_yesno = create_yesno( ); default_ans = ans; fli_parse_goodies_label( fd_yesno->yes, FLQuestionYesLabel ); fli_parse_goodies_label( fd_yesno->no, FLQuestionNoLabel ); /* We don't set a shortcut if the first letter of the "yes" label is identical to all letters in the "no" label */ while ( fd_yesno->no->label[ k ] && tolower( ( int ) fd_yesno->yes->label[ 0 ] ) == tolower( ( int ) fd_yesno->yes->label[ k ] ) ) k++; if ( fd_yesno->no->label[ k ] ) { shortcut[ 0 ] = fd_yesno->yes->label[ 0 ]; shortcut[ 1 ] = tolower( ( int ) fd_yesno->yes->label[ 0 ] ); shortcut[ 2 ] = toupper( ( int ) fd_yesno->yes->label[ 0 ] ); shortcut[ 3 ] = '\0'; fl_set_button_shortcut( fd_yesno->yes, shortcut, 1 ); shortcut[ 0 ] = fd_yesno->no->label[ k ]; shortcut[ 1 ] = toupper( ( int ) fd_yesno->no->label[ k ] ); shortcut[ 2 ] = tolower( ( int ) fd_yesno->no->label[ k ] ); fl_set_button_shortcut( fd_yesno->no, shortcut, 1 ); } fli_get_goodie_title( fd_yesno->form, FLQuestionTitle ); fli_handle_goodie_font( fd_yesno->yes, fd_yesno->str ); fli_handle_goodie_font( fd_yesno->no, NULL ); fl_set_object_label( fd_yesno->str, str ); if ( ans == 1 ) fl_set_form_hotobject( fd_yesno->form, fd_yesno->yes ); else if ( ans == 0 ) fl_set_form_hotobject( fd_yesno->form, fd_yesno->no ); else fl_set_form_hotspot( fd_yesno->form, -1, -1 ); fl_show_form( fd_yesno->form, FL_PLACE_HOTSPOT, FL_TRANSIENT, fd_yesno->form->label ); fl_update_display( 0 ); while ( ( retobj = fl_do_only_forms( ) ) != fd_yesno->yes && retobj != fd_yesno->no ) /* empty */; k = retobj == fd_yesno->yes; fl_hide_form( fd_yesno->form ); fl_free_form( fd_yesno->form ); fli_safe_free( fd_yesno ); fl_activate_all_forms( ); return k; }
int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen) { int uninitialized_var(err); struct net *net = sock_net(sk); struct ipv6_pinfo *np = inet6_sk(sk); struct in6_flowlabel_req freq; struct ipv6_fl_socklist *sfl1=NULL; struct ipv6_fl_socklist *sfl, **sflp; struct ip6_flowlabel *fl, *fl1 = NULL; if (optlen < sizeof(freq)) return -EINVAL; if (copy_from_user(&freq, optval, sizeof(freq))) return -EFAULT; switch (freq.flr_action) { case IPV6_FL_A_PUT: write_lock_bh(&ip6_sk_fl_lock); for (sflp = &np->ipv6_fl_list; (sfl=*sflp)!=NULL; sflp = &sfl->next) { if (sfl->fl->label == freq.flr_label) { if (freq.flr_label == (np->flow_label&IPV6_FLOWLABEL_MASK)) np->flow_label &= ~IPV6_FLOWLABEL_MASK; *sflp = sfl->next; write_unlock_bh(&ip6_sk_fl_lock); fl_release(sfl->fl); kfree(sfl); return 0; } } write_unlock_bh(&ip6_sk_fl_lock); return -ESRCH; case IPV6_FL_A_RENEW: read_lock_bh(&ip6_sk_fl_lock); for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) { if (sfl->fl->label == freq.flr_label) { err = fl6_renew(sfl->fl, freq.flr_linger, freq.flr_expires); read_unlock_bh(&ip6_sk_fl_lock); return err; } } read_unlock_bh(&ip6_sk_fl_lock); if (freq.flr_share == IPV6_FL_S_NONE && capable(CAP_NET_ADMIN)) { fl = fl_lookup(net, freq.flr_label); if (fl) { err = fl6_renew(fl, freq.flr_linger, freq.flr_expires); fl_release(fl); return err; } } return -ESRCH; case IPV6_FL_A_GET: if (freq.flr_label & ~IPV6_FLOWLABEL_MASK) return -EINVAL; fl = fl_create(net, sk, &freq, optval, optlen, &err); if (fl == NULL) return err; sfl1 = kmalloc(sizeof(*sfl1), GFP_KERNEL); if (freq.flr_label) { err = -EEXIST; read_lock_bh(&ip6_sk_fl_lock); for (sfl = np->ipv6_fl_list; sfl; sfl = sfl->next) { if (sfl->fl->label == freq.flr_label) { if (freq.flr_flags&IPV6_FL_F_EXCL) { read_unlock_bh(&ip6_sk_fl_lock); goto done; } fl1 = sfl->fl; atomic_inc(&fl1->users); break; } } read_unlock_bh(&ip6_sk_fl_lock); if (fl1 == NULL) fl1 = fl_lookup(net, freq.flr_label); if (fl1) { recheck: err = -EEXIST; if (freq.flr_flags&IPV6_FL_F_EXCL) goto release; err = -EPERM; if (fl1->share == IPV6_FL_S_EXCL || fl1->share != fl->share || fl1->owner != fl->owner) goto release; err = -EINVAL; if (!ipv6_addr_equal(&fl1->dst, &fl->dst) || ipv6_opt_cmp(fl1->opt, fl->opt)) goto release; err = -ENOMEM; if (sfl1 == NULL) goto release; if (fl->linger > fl1->linger) fl1->linger = fl->linger; if ((long)(fl->expires - fl1->expires) > 0) fl1->expires = fl->expires; fl_link(np, sfl1, fl1); fl_free(fl); return 0; release: fl_release(fl1); goto done; } } err = -ENOENT; if (!(freq.flr_flags&IPV6_FL_F_CREATE)) goto done; err = -ENOMEM; if (sfl1 == NULL || (err = mem_check(sk)) != 0) goto done; fl1 = fl_intern(net, fl, freq.flr_label); if (fl1 != NULL) goto recheck; if (!freq.flr_label) { if (copy_to_user(&((struct in6_flowlabel_req __user *) optval)->flr_label, &fl->label, sizeof(fl->label))) { /* Intentionally ignore fault. */ } } fl_link(np, sfl1, fl); return 0; default: return -EINVAL; } done: fl_free(fl); kfree(sfl1); return err; }
static struct ip6_flowlabel * fl_create(struct net *net, struct sock *sk, struct in6_flowlabel_req *freq, char __user *optval, int optlen, int *err_p) { struct ip6_flowlabel *fl = NULL; int olen; int addr_type; int err; olen = optlen - CMSG_ALIGN(sizeof(*freq)); err = -EINVAL; if (olen > 64 * 1024) goto done; err = -ENOMEM; fl = kzalloc(sizeof(*fl), GFP_KERNEL); if (fl == NULL) goto done; if (olen > 0) { struct msghdr msg; struct flowi6 flowi6; int junk; err = -ENOMEM; fl->opt = kmalloc(sizeof(*fl->opt) + olen, GFP_KERNEL); if (fl->opt == NULL) goto done; memset(fl->opt, 0, sizeof(*fl->opt)); fl->opt->tot_len = sizeof(*fl->opt) + olen; err = -EFAULT; if (copy_from_user(fl->opt+1, optval+CMSG_ALIGN(sizeof(*freq)), olen)) goto done; msg.msg_controllen = olen; msg.msg_control = (void*)(fl->opt+1); memset(&flowi6, 0, sizeof(flowi6)); err = datagram_send_ctl(net, sk, &msg, &flowi6, fl->opt, &junk, &junk, &junk); if (err) goto done; err = -EINVAL; if (fl->opt->opt_flen) goto done; if (fl->opt->opt_nflen == 0) { kfree(fl->opt); fl->opt = NULL; } } fl->fl_net = hold_net(net); fl->expires = jiffies; err = fl6_renew(fl, freq->flr_linger, freq->flr_expires); if (err) goto done; fl->share = freq->flr_share; addr_type = ipv6_addr_type(&freq->flr_dst); if ((addr_type & IPV6_ADDR_MAPPED) || addr_type == IPV6_ADDR_ANY) { err = -EINVAL; goto done; } fl->dst = freq->flr_dst; atomic_set(&fl->users, 1); switch (fl->share) { case IPV6_FL_S_EXCL: case IPV6_FL_S_ANY: break; case IPV6_FL_S_PROCESS: fl->owner = current->pid; break; case IPV6_FL_S_USER: fl->owner = current_euid(); break; default: err = -EINVAL; goto done; } return fl; done: fl_free(fl); *err_p = err; return NULL; }
SuperSPEC * spec_to_superspec( FL_OBJECT * obj ) { SuperSPEC *ssp; int i; int n; if ( ! obj->u_vdata ) { obj->u_vdata = ssp = fl_calloc( 1, sizeof *ssp ); ssp->content = NULL; ssp->shortcut = NULL; ssp->callback = NULL; ssp->mode = NULL; ssp->mval = NULL; ssp->misc_char = NULL; ssp->new_menuapi = 0; ssp->nlines = 0; } else ssp = obj->u_vdata; if ( obj->objclass == FL_BROWSER ) { FLI_BROWSER_SPEC *sp = obj->spec; ssp->h_pref = sp->h_pref; ssp->v_pref = sp->v_pref; for ( i = 1; i <= ssp->nlines; i++ ) fl_free( ssp->content[ i ] ); n = ssp->nlines = fl_get_browser_maxline( obj ); ssp->content = fl_realloc( ssp->content, ( n + 1 ) * sizeof *ssp->content ); for ( i = 1; i <= n; i++ ) ssp->content[ i ] = fl_strdup( fl_get_browser_line( obj, i ) ); } else if ( obj->objclass == FL_CHOICE ) { FLI_CHOICE_SPEC *sp = obj->spec; for ( i = 1; i <= ssp->nlines; i++ ) { fl_free( ssp->content[ i ] ); fl_free( ssp->shortcut[ i ] ); } n = ssp->nlines = sp->numitems; ssp->content = fl_realloc( ssp->content, ( n + 1 ) * sizeof *ssp->content ); ssp->shortcut = fl_realloc( ssp->shortcut, ( n + 1 ) * sizeof *ssp->shortcut ); ssp->mode = fl_realloc( ssp->mode, ( n + 1 ) * sizeof *ssp->mode ); ssp->align = sp->align; ssp->int_val = sp->val; for ( i = 1; i <= n; i++ ) { ssp->content[ i ] = fl_strdup( fl_get_choice_item_text( obj, i ) ); if ( sp->shortcut[ i ] ) ssp->shortcut[ i ] = fl_strdup( sp->shortcut[ i ] ); else ssp->shortcut[ i ] = NULL; } memcpy( ssp->mode, sp->mode, ( n + 1 ) * sizeof *ssp->mode ); } else if ( obj->objclass == FL_MENU ) { FLI_MENU_SPEC *sp = obj->spec; for ( i = 1; i <= ssp->nlines; i++ ) { fl_free( ssp->content[ i ] ); fl_free( ssp->shortcut[ i ] ); fl_free( ssp->callback[ i ] ); } n = ssp->nlines = sp->numitems; ssp->content = fl_realloc( ssp->content, ( n + 1 ) * sizeof *ssp->content ); ssp->shortcut = fl_realloc( ssp->shortcut, ( n + 1 ) * sizeof *ssp->shortcut ); ssp->callback = fl_realloc( ssp->callback, ( n + 1 ) * sizeof *ssp->callback ); ssp->mode = fl_realloc( ssp->mode, ( n + 1 ) * sizeof *ssp->mode ); ssp->mval = fl_realloc( ssp->mval, ( n + 1 ) * sizeof *ssp->mval ); for ( i = 1; i <= n; i++ ) { ssp->content[ i ] = fl_strdup( fl_get_menu_item_text( obj, sp->mval[ i ] ) ); if ( sp->shortcut[ i ] ) ssp->shortcut[ i ] = fl_strdup( sp->shortcut[ i ] ); else ssp->shortcut[ i ] = NULL; if ( sp->cb[ i ] ) ssp->callback[ i ] = fl_strdup( ( char * ) sp->cb[ i ] ); else ssp->callback[ i ] = NULL; } memcpy( ssp->mode, sp->mode, ( n + 1 ) * sizeof *ssp->mode ); memcpy( ssp->mval, sp->mval, ( n + 1 ) * sizeof *ssp->mval ); } else if ( obj->objclass == FL_SLIDER || obj->objclass == FL_VALSLIDER || obj->objclass == FL_THUMBWHEEL ) { FLI_SLIDER_SPEC *sp = obj->spec; ssp->val = sp->val; ssp->min = sp->min; ssp->max = sp->max; ssp->step = sp->step; ssp->prec = sp->prec; ssp->ldelta = sp->ldelta; ssp->rdelta = sp->rdelta; ssp->slsize = sp->slsize; } else if ( ISBUTTON( obj->objclass ) || obj->objclass == FL_PIXMAP || obj->objclass == FL_BITMAP ) { FL_BUTTON_SPEC *sp = obj->spec; ssp->mbuttons = 0; for ( i = 0; i < 5; i++ ) if ( sp->react_to[ i ] ) ssp->mbuttons |= 1 << i; ssp->int_val = sp->val; } else if ( obj->objclass == FL_POSITIONER ) { FLI_POSITIONER_SPEC *sp = obj->spec; ssp->xstep = sp->xstep; ssp->ystep = sp->ystep; ssp->xmin = sp->xmin; ssp->xmax = sp->xmax; ssp->xval = sp->xval; ssp->ymin = sp->ymin; ssp->ymax = sp->ymax; ssp->yval = sp->yval; } else if ( obj->objclass == FL_COUNTER ) { FLI_COUNTER_SPEC *sp = obj->spec; ssp->val = sp->val; ssp->lstep = sp->lstep; ssp->sstep = sp->sstep; ssp->min = sp->min; ssp->max = sp->max; ssp->prec = sp->prec; } else if ( obj->objclass == FL_DIAL ) { FLI_DIAL_SPEC *sp = obj->spec; ssp->min = sp->min; ssp->max = sp->max; ssp->val = sp->val; ssp->step = sp->step; ssp->thetai = sp->thetai; ssp->thetaf = sp->thetaf; ssp->direction = sp->direction; } else if ( obj->objclass == FL_XYPLOT ) { FLI_XYPLOT_SPEC *sp = obj->spec; ssp->xmajor = sp->xmajor; ssp->xminor = sp->xminor; ssp->ymajor = sp->ymajor; ssp->yminor = sp->yminor; ssp->xscale = sp->xscale; ssp->yscale = sp->yscale; ssp->xgrid = sp->xgrid; ssp->ygrid = sp->ygrid; ssp->grid_linestyle = sp->grid_linestyle; ssp->xbase = sp->xbase; ssp->ybase = sp->ybase; ssp->mark_active = sp->mark_active; } else if ( obj->objclass == FL_SCROLLBAR ) { FLI_SCROLLBAR_SPEC *scbsp = obj->spec; FLI_SLIDER_SPEC *sp = scbsp->slider->spec; ssp->val = sp->val; ssp->min = sp->min; ssp->max = sp->max; ssp->prec = sp->prec; ssp->step = sp->step; ssp->slsize = sp->slsize; ssp->ldelta = sp->ldelta; ssp->rdelta = sp->rdelta; } else if ( obj->objclass == FL_SPINNER ) { FLI_SPINNER_SPEC *sp = obj->spec; ssp->val = fl_get_spinner_value( obj ); fl_get_spinner_bounds( obj, &ssp->min, &ssp->max ); ssp->step = fl_get_spinner_step( obj ); ssp->prec = fl_get_spinner_precision( obj ); ssp->orient = sp->orient; } return ssp; }
int ipv6_flowlabel_opt(struct sock *sk, char __user *optval, int optlen) { int uninitialized_var(err); struct net *net = sock_net(sk); struct ipv6_pinfo *np = inet6_sk(sk); struct in6_flowlabel_req freq; struct ipv6_fl_socklist *sfl1 = NULL; struct ipv6_fl_socklist *sfl; struct ipv6_fl_socklist __rcu **sflp; struct ip6_flowlabel *fl, *fl1 = NULL; if (optlen < sizeof(freq)) return -EINVAL; if (copy_from_user(&freq, optval, sizeof(freq))) return -EFAULT; switch (freq.flr_action) { case IPV6_FL_A_PUT: if (freq.flr_flags & IPV6_FL_F_REFLECT) { if (sk->sk_protocol != IPPROTO_TCP) return -ENOPROTOOPT; if (!np->repflow) return -ESRCH; np->flow_label = 0; np->repflow = 0; return 0; } spin_lock_bh(&ip6_sk_fl_lock); for (sflp = &np->ipv6_fl_list; (sfl = rcu_dereference(*sflp)) != NULL; sflp = &sfl->next) { if (sfl->fl->label == freq.flr_label) { if (freq.flr_label == (np->flow_label&IPV6_FLOWLABEL_MASK)) np->flow_label &= ~IPV6_FLOWLABEL_MASK; *sflp = rcu_dereference(sfl->next); spin_unlock_bh(&ip6_sk_fl_lock); fl_release(sfl->fl); kfree_rcu(sfl, rcu); return 0; } } spin_unlock_bh(&ip6_sk_fl_lock); return -ESRCH; case IPV6_FL_A_RENEW: rcu_read_lock_bh(); for_each_sk_fl_rcu(np, sfl) { if (sfl->fl->label == freq.flr_label) { err = fl6_renew(sfl->fl, freq.flr_linger, freq.flr_expires); rcu_read_unlock_bh(); return err; } } rcu_read_unlock_bh(); if (freq.flr_share == IPV6_FL_S_NONE && ns_capable(net->user_ns, CAP_NET_ADMIN)) { fl = fl_lookup(net, freq.flr_label); if (fl) { err = fl6_renew(fl, freq.flr_linger, freq.flr_expires); fl_release(fl); return err; } } return -ESRCH; case IPV6_FL_A_GET: if (freq.flr_flags & IPV6_FL_F_REFLECT) { struct net *net = sock_net(sk); if (net->ipv6.sysctl.flowlabel_consistency) { net_info_ratelimited("Can not set IPV6_FL_F_REFLECT if flowlabel_consistency sysctl is enable\n"); return -EPERM; } if (sk->sk_protocol != IPPROTO_TCP) return -ENOPROTOOPT; np->repflow = 1; return 0; } if (freq.flr_label & ~IPV6_FLOWLABEL_MASK) return -EINVAL; fl = fl_create(net, sk, &freq, optval, optlen, &err); if (!fl) return err; sfl1 = kmalloc(sizeof(*sfl1), GFP_KERNEL); if (freq.flr_label) { err = -EEXIST; rcu_read_lock_bh(); for_each_sk_fl_rcu(np, sfl) { if (sfl->fl->label == freq.flr_label) { if (freq.flr_flags&IPV6_FL_F_EXCL) { rcu_read_unlock_bh(); goto done; } fl1 = sfl->fl; atomic_inc(&fl1->users); break; } } rcu_read_unlock_bh(); if (!fl1) fl1 = fl_lookup(net, freq.flr_label); if (fl1) { recheck: err = -EEXIST; if (freq.flr_flags&IPV6_FL_F_EXCL) goto release; err = -EPERM; if (fl1->share == IPV6_FL_S_EXCL || fl1->share != fl->share || ((fl1->share == IPV6_FL_S_PROCESS) && (fl1->owner.pid == fl->owner.pid)) || ((fl1->share == IPV6_FL_S_USER) && uid_eq(fl1->owner.uid, fl->owner.uid))) goto release; err = -ENOMEM; if (!sfl1) goto release; if (fl->linger > fl1->linger) fl1->linger = fl->linger; if ((long)(fl->expires - fl1->expires) > 0) fl1->expires = fl->expires; fl_link(np, sfl1, fl1); fl_free(fl); return 0; release: fl_release(fl1); goto done; } } err = -ENOENT; if (!(freq.flr_flags&IPV6_FL_F_CREATE)) goto done; err = -ENOMEM; if (!sfl1) goto done; err = mem_check(sk); if (err != 0) goto done; fl1 = fl_intern(net, fl, freq.flr_label); if (fl1) goto recheck; if (!freq.flr_label) { if (copy_to_user(&((struct in6_flowlabel_req __user *) optval)->flr_label, &fl->label, sizeof(fl->label))) { /* Intentionally ignore fault. */ } } fl_link(np, sfl1, fl); return 0; default: return -EINVAL; }
int main(int argc, char** args) { int argchar; kdtree_t* kd; int Nleaf = 25; char* infn = NULL; char* outfn = NULL; char* tychofn = NULL; char* crossfn = NULL; char* progname = args[0]; FILE* f; tycstar_t* tycstars = NULL; int Ntyc = 0; int exttype = KDT_EXT_DOUBLE; int datatype = KDT_DATA_U32; int treetype = KDT_TREE_U32; int tt; int buildopts = 0; int i, N, D; dl* ras; dl* decs; dl* hds; fl* mag1s; fl* mag2s; fl* mag3s; int nbad = 0; int nox = 0; int* hd; double* xyz; qfits_header* hdr; while ((argchar = getopt (argc, args, OPTIONS)) != -1) switch (argchar) { case 'T': tychofn = optarg; break; case 'X': crossfn = optarg; break; case 'R': Nleaf = (int)strtoul(optarg, NULL, 0); break; case 't': treetype = kdtree_kdtype_parse_tree_string(optarg); break; case 'd': datatype = kdtree_kdtype_parse_data_string(optarg); break; case 'b': buildopts |= KD_BUILD_BBOX; break; case 's': buildopts |= KD_BUILD_SPLIT; break; case 'S': buildopts |= KD_BUILD_SPLITDIM; break; case '?': fprintf(stderr, "Unknown option `-%c'.\n", optopt); case 'h': printHelp(progname); return 0; default: return -1; } if (optind != argc - 2) { printHelp(progname); exit(-1); } infn = args[optind]; outfn = args[optind+1]; if (!(buildopts & (KD_BUILD_BBOX | KD_BUILD_SPLIT))) { printf("You need bounding-boxes or splitting planes!\n"); printHelp(progname); exit(-1); } if (tychofn || crossfn) { if (!(tychofn && crossfn)) { printf("You need both -T <Tycho2> and -X <Crossref> to do cross-referencing.\n"); exit(-1); } } if (tychofn) { int i, N; tycho2_fits* tyc; FILE* f; int nx, nox; int lastgrass = 0; tyc = tycho2_fits_open(tychofn); if (!tyc) { ERROR("Failed to open Tycho-2 catalog."); exit(-1); } printf("Reading Tycho-2 catalog...\n"); N = tycho2_fits_count_entries(tyc); tycstars = calloc(N, sizeof(tycstar_t)); for (i=0; i<N; i++) { tycho2_entry* te; int grass = (i*80 / N); if (grass != lastgrass) { printf("."); fflush(stdout); lastgrass = grass; } te = tycho2_fits_read_entry(tyc); tycstars[i].tyc1 = te->tyc1; tycstars[i].tyc2 = te->tyc2; tycstars[i].tyc3 = te->tyc3; tycstars[i].ra = te->ra; tycstars[i].dec = te->dec; tycstars[i].mag_BT = te->mag_BT; tycstars[i].mag_VT = te->mag_VT; tycstars[i].mag_HP = te->mag_HP; } tycho2_fits_close(tyc); printf("Sorting...\n"); qsort(tycstars, N, sizeof(tycstar_t), compare_tycs); Ntyc = N; f = fopen(crossfn, "rb"); if (!f) { SYSERROR("Failed to open cross-reference file %s", crossfn); exit(-1); } nx = 0; nox = 0; while (TRUE) { char buf[1024]; int tyc1, tyc2, tyc3, hd, nhd, ntyc; char ftyc, sptype0, sptype1, sptype2; tycstar_t* s; if (!fgets(buf, sizeof(buf), f)) { if (ferror(f)) { SYSERROR("Failed to read a line of text from the cross-reference file"); exit(-1); } break; } if (sscanf(buf, " %d %d %d%c %d %c%c%c %d %d", &tyc1, &tyc2, &tyc3, &ftyc, &hd, &sptype0, &sptype1, &sptype2, &nhd, &ntyc) != 10) { ERROR("Failed to parse line: \"%s\"", buf); } //printf("%i %i %i %i %i %i\n", tyc1, tyc2, tyc3, hd, nhd, ntyc); s = find_tycho(tycstars, Ntyc, tyc1, tyc2, tyc3); if (!s) { ERROR("Failed to find Tycho-2 star %i-%i-%i", tyc1, tyc2, tyc3); nox++; } else { s->hd = hd; s->ntyc = ntyc; } nx++; } fclose(f); printf("Read %i cross-references.\n", nx); printf("Failed to find %i cross-referenced Tycho-2 stars.\n", nox); printf("Sorting...\n"); qsort(tycstars, N, sizeof(tycstar_t), compare_hds); } f = fopen(infn, "rb"); if (!f) { SYSERROR("Failed to open input file %s", infn); exit(-1); } ras = dl_new(1024); decs = dl_new(1024); hds = il_new(1024); mag1s = fl_new(1024); mag2s = fl_new(1024); mag3s = fl_new(1024); printf("Reading HD catalog...\n"); for (;;) { char buf[1024]; double ra, dec; int hd; float mag1, mag2, mag3; mag1 = mag2 = mag3 = 0.0; if (!fgets(buf, sizeof(buf), f)) { if (ferror(f)) { SYSERROR("Failed to read a line of text from the input file"); exit(-1); } break; } if (buf[0] == '#') continue; if (buf[0] == '\n') continue; if (sscanf(buf, " %lf| %lf| %d", &ra, &dec, &hd) < 3) { // ignore three invalid lines if (nbad > 3) { ERROR("Failed to parse line: \"%s\"", buf); } nbad++; } else { if (tycstars) { tycstar_t* s = find_hd(tycstars, Ntyc, hd); if (!s) { //printf("Failed to find cross-ref for HD %i\n", hd); nox++; } else { ra = s->ra; dec = s->dec; mag1 = s->mag_VT; mag2 = s->mag_BT; mag3 = s->mag_HP; } } dl_append(ras, ra); dl_append(decs, dec); il_append(hds, hd); fl_append(mag1s, mag1); fl_append(mag2s, mag2); fl_append(mag3s, mag3); } } fclose(f); N = dl_size(ras); printf("Read %i entries and %i bad lines.\n", N, nbad); if (dl_size(ras) != HD_NENTRIES) { printf("WARNING: expected %i Henry Draper catalog entries.\n", HD_NENTRIES); } if (nox) { printf("Found %i HD entries with no cross-reference (expect this to be about 1%%)\n", nox); } hd = malloc(sizeof(int) * N); il_copy(hds, 0, N, hd); il_free(hds); for (i=0; i<N; i++) if (hd[i] != i+1) { printf("Line %i is HD %i\n", i+1, hd[i]); break; } // HACK - don't allocate 'em in the first place... free(hd); xyz = malloc(sizeof(double) * 3 * N); for (i=0; i<N; i++) { radecdeg2xyzarr(dl_get(ras, i), dl_get(decs, i), xyz + 3*i); } dl_free(ras); dl_free(decs); tt = kdtree_kdtypes_to_treetype(exttype, treetype, datatype); D = 3; { // limits of the kdtree... double lo[] = {-1.0, -1.0, -1.0}; double hi[] = { 1.0, 1.0, 1.0}; kd = kdtree_new(N, D, Nleaf); kdtree_set_limits(kd, lo, hi); } printf("Building tree...\n"); kd = kdtree_build(kd, xyz, N, D, Nleaf, tt, buildopts); hdr = qfits_header_default(); qfits_header_add(hdr, "AN_FILE", "HDTREE", "Henry Draper catalog kdtree", NULL); BOILERPLATE_ADD_FITS_HEADERS(hdr); fits_add_long_history(hdr, "This file was created by the following command-line:"); fits_add_args(hdr, args, argc); if (kdtree_fits_write(kd, outfn, hdr)) { ERROR("Failed to write kdtree"); exit(-1); } // Write mags as tag-along table. { fitstable_t* tag; tag = fitstable_open_for_appending(outfn); if (!tag) { ERROR("Failed to open kd-tree file for appending"); exit(-1); } fitstable_add_write_column(tag, fitscolumn_float_type(), "MAG_VT", ""); fitstable_add_write_column(tag, fitscolumn_float_type(), "MAG_BT", ""); fitstable_add_write_column(tag, fitscolumn_float_type(), "MAG_HP", ""); if (fitstable_write_header(tag)) { ERROR("Failed to write tag-along header"); exit(-1); } for (i=0; i<N; i++) { fitstable_write_row(tag, fl_get(mag1s, i), fl_get(mag2s, i), fl_get(mag3s, i)); } if (fitstable_fix_header(tag)) { ERROR("Failed to fix tag-along header"); exit(-1); } if (fitstable_close(tag)) { ERROR("Failed to close tag-along data"); exit(-1); } } fl_free(mag1s); fl_free(mag2s); fl_free(mag3s); printf("Done.\n"); qfits_header_destroy(hdr); free(xyz); kdtree_free(kd); free(tycstars); return 0; }
static int BMP_description( FL_IMAGE * im ) { SPEC *sp = fl_calloc( 1, sizeof *sp ); char buf[ 40 ]; if ( fread( buf, 1, 2, im->fpin ) != 2 ) { im->error_message( im, "error while readin bmp file" ); fl_free( sp ); return -1; } sp->fsize = fli_fget4LSBF( im->fpin ); if ( fread( buf, 1, 4, im->fpin ) != 4 ) { im->error_message( im, "error while reading bmp file" ); fl_free( sp ); return -1; } sp->offset = fli_fget4LSBF( im->fpin ); sp->infosize = fli_fget4LSBF( im->fpin ); if ( sp->infosize != 40 && sp->infosize != 64 ) { im->error_message( im, "unsupported old obsolete bmp file" ); fl_free( sp ); return -1; } im->io_spec = sp; sp->w = fli_fget4LSBF( im->fpin ); sp->h = fli_fget4LSBF( im->fpin ); sp->planes = fli_fget2LSBF( im->fpin ); sp->bpp = fli_fget2LSBF( im->fpin ); sp->encode = fli_fget4LSBF( im->fpin ); sp->isize = fli_fget4LSBF( im->fpin ); sp->xres = fli_fget4LSBF( im->fpin ); sp->yres = fli_fget4LSBF(im->fpin); sp->col_used = fli_fget4LSBF( im->fpin ); sp->col_important = fli_fget4LSBF( im->fpin ); if ( bad_bpp( sp->bpp ) ) { flimage_error( im, "%s: bad bpp (%d)", im->infile, sp->bpp ); fl_free( im->io_spec ); im->io_spec = 0; return -1; } if ( sp->infosize != 40 ) { int skip = sp->infosize - 40; if ( skip < 0 || fread( buf, 1, skip, im->fpin ) != ( size_t ) skip ) { flimage_error( im, "%s: error while reading bmp file", im->infile ); fl_free( im->io_spec ); im->io_spec = 0; return -1; } } im->w = sp->w; im->h = sp->h; /* read colormap */ if ( sp->bpp != 24 ) { int i; if ( ( im->map_len = sp->col_used ) <= 0 ) im->map_len = 1 << sp->bpp; flimage_getcolormap( im ); for ( i = 0; i < im->map_len; i++ ) { im->blue_lut[ i ] = getc( im->fpin ); im->green_lut[ i ] = getc( im->fpin ); im->red_lut[ i ] = getc( im->fpin ); im->alpha_lut[ i ] = getc( im->fpin ); } } sp->bpl = ( sp->w * sp->bpp + 7 ) / 8; sp->pad = ( ( sp->bpl + 3 ) / 4 ) * 4 - sp->bpl; /* pad to 4 bytes */ if ( sp->bpp == 24 ) im->type = FL_IMAGE_RGB; else if ( sp->bpp == 1 ) im->type = FL_IMAGE_MONO; else im->type = FL_IMAGE_CI; #if BMPDEBUG dump_header( "after read", sp ); #endif if ( im->setup->header_info ) generate_header_info( im ); return 1; }