1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154 |
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/COPYING flatpak-builder-0.10.6/libglnx/COPYING
- --- flatpak-builder-0.10.6.orig/libglnx/COPYING 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/COPYING 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,502 @@
- + GNU LESSER GENERAL PUBLIC LICENSE
- + Version 2.1, February 1999
- +
- + Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- + Everyone is permitted to copy and distribute verbatim copies
- + of this license document, but changing it is not allowed.
- +
- +[This is the first released version of the Lesser GPL. It also counts
- + as the successor of the GNU Library Public License, version 2, hence
- + the version number 2.1.]
- +
- + Preamble
- +
- + The licenses for most software are designed to take away your
- +freedom to share and change it. By contrast, the GNU General Public
- +Licenses are intended to guarantee your freedom to share and change
- +free software--to make sure the software is free for all its users.
- +
- + This license, the Lesser General Public License, applies to some
- +specially designated software packages--typically libraries--of the
- +Free Software Foundation and other authors who decide to use it. You
- +can use it too, but we suggest you first think carefully about whether
- +this license or the ordinary General Public License is the better
- +strategy to use in any particular case, based on the explanations below.
- +
- + When we speak of free software, we are referring to freedom of use,
- +not price. Our General Public Licenses are designed to make sure that
- +you have the freedom to distribute copies of free software (and charge
- +for this service if you wish); that you receive source code or can get
- +it if you want it; that you can change the software and use pieces of
- +it in new free programs; and that you are informed that you can do
- +these things.
- +
- + To protect your rights, we need to make restrictions that forbid
- +distributors to deny you these rights or to ask you to surrender these
- +rights. These restrictions translate to certain responsibilities for
- +you if you distribute copies of the library or if you modify it.
- +
- + For example, if you distribute copies of the library, whether gratis
- +or for a fee, you must give the recipients all the rights that we gave
- +you. You must make sure that they, too, receive or can get the source
- +code. If you link other code with the library, you must provide
- +complete object files to the recipients, so that they can relink them
- +with the library after making changes to the library and recompiling
- +it. And you must show them these terms so they know their rights.
- +
- + We protect your rights with a two-step method: (1) we copyright the
- +library, and (2) we offer you this license, which gives you legal
- +permission to copy, distribute and/or modify the library.
- +
- + To protect each distributor, we want to make it very clear that
- +there is no warranty for the free library. Also, if the library is
- +modified by someone else and passed on, the recipients should know
- +that what they have is not the original version, so that the original
- +author's reputation will not be affected by problems that might be
- +introduced by others.
- +
- + Finally, software patents pose a constant threat to the existence of
- +any free program. We wish to make sure that a company cannot
- +effectively restrict the users of a free program by obtaining a
- +restrictive license from a patent holder. Therefore, we insist that
- +any patent license obtained for a version of the library must be
- +consistent with the full freedom of use specified in this license.
- +
- + Most GNU software, including some libraries, is covered by the
- +ordinary GNU General Public License. This license, the GNU Lesser
- +General Public License, applies to certain designated libraries, and
- +is quite different from the ordinary General Public License. We use
- +this license for certain libraries in order to permit linking those
- +libraries into non-free programs.
- +
- + When a program is linked with a library, whether statically or using
- +a shared library, the combination of the two is legally speaking a
- +combined work, a derivative of the original library. The ordinary
- +General Public License therefore permits such linking only if the
- +entire combination fits its criteria of freedom. The Lesser General
- +Public License permits more lax criteria for linking other code with
- +the library.
- +
- + We call this license the "Lesser" General Public License because it
- +does Less to protect the user's freedom than the ordinary General
- +Public License. It also provides other free software developers Less
- +of an advantage over competing non-free programs. These disadvantages
- +are the reason we use the ordinary General Public License for many
- +libraries. However, the Lesser license provides advantages in certain
- +special circumstances.
- +
- + For example, on rare occasions, there may be a special need to
- +encourage the widest possible use of a certain library, so that it becomes
- +a de-facto standard. To achieve this, non-free programs must be
- +allowed to use the library. A more frequent case is that a free
- +library does the same job as widely used non-free libraries. In this
- +case, there is little to gain by limiting the free library to free
- +software only, so we use the Lesser General Public License.
- +
- + In other cases, permission to use a particular library in non-free
- +programs enables a greater number of people to use a large body of
- +free software. For example, permission to use the GNU C Library in
- +non-free programs enables many more people to use the whole GNU
- +operating system, as well as its variant, the GNU/Linux operating
- +system.
- +
- + Although the Lesser General Public License is Less protective of the
- +users' freedom, it does ensure that the user of a program that is
- +linked with the Library has the freedom and the wherewithal to run
- +that program using a modified version of the Library.
- +
- + The precise terms and conditions for copying, distribution and
- +modification follow. Pay close attention to the difference between a
- +"work based on the library" and a "work that uses the library". The
- +former contains code derived from the library, whereas the latter must
- +be combined with the library in order to run.
- +
- + GNU LESSER GENERAL PUBLIC LICENSE
- + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- +
- + 0. This License Agreement applies to any software library or other
- +program which contains a notice placed by the copyright holder or
- +other authorized party saying it may be distributed under the terms of
- +this Lesser General Public License (also called "this License").
- +Each licensee is addressed as "you".
- +
- + A "library" means a collection of software functions and/or data
- +prepared so as to be conveniently linked with application programs
- +(which use some of those functions and data) to form executables.
- +
- + The "Library", below, refers to any such software library or work
- +which has been distributed under these terms. A "work based on the
- +Library" means either the Library or any derivative work under
- +copyright law: that is to say, a work containing the Library or a
- +portion of it, either verbatim or with modifications and/or translated
- +straightforwardly into another language. (Hereinafter, translation is
- +included without limitation in the term "modification".)
- +
- + "Source code" for a work means the preferred form of the work for
- +making modifications to it. For a library, complete source code means
- +all the source code for all modules it contains, plus any associated
- +interface definition files, plus the scripts used to control compilation
- +and installation of the library.
- +
- + Activities other than copying, distribution and modification are not
- +covered by this License; they are outside its scope. The act of
- +running a program using the Library is not restricted, and output from
- +such a program is covered only if its contents constitute a work based
- +on the Library (independent of the use of the Library in a tool for
- +writing it). Whether that is true depends on what the Library does
- +and what the program that uses the Library does.
- +
- + 1. You may copy and distribute verbatim copies of the Library's
- +complete source code as you receive it, in any medium, provided that
- +you conspicuously and appropriately publish on each copy an
- +appropriate copyright notice and disclaimer of warranty; keep intact
- +all the notices that refer to this License and to the absence of any
- +warranty; and distribute a copy of this License along with the
- +Library.
- +
- + You may charge a fee for the physical act of transferring a copy,
- +and you may at your option offer warranty protection in exchange for a
- +fee.
- +
- + 2. You may modify your copy or copies of the Library or any portion
- +of it, thus forming a work based on the Library, and copy and
- +distribute such modifications or work under the terms of Section 1
- +above, provided that you also meet all of these conditions:
- +
- + a) The modified work must itself be a software library.
- +
- + b) You must cause the files modified to carry prominent notices
- + stating that you changed the files and the date of any change.
- +
- + c) You must cause the whole of the work to be licensed at no
- + charge to all third parties under the terms of this License.
- +
- + d) If a facility in the modified Library refers to a function or a
- + table of data to be supplied by an application program that uses
- + the facility, other than as an argument passed when the facility
- + is invoked, then you must make a good faith effort to ensure that,
- + in the event an application does not supply such function or
- + table, the facility still operates, and performs whatever part of
- + its purpose remains meaningful.
- +
- + (For example, a function in a library to compute square roots has
- + a purpose that is entirely well-defined independent of the
- + application. Therefore, Subsection 2d requires that any
- + application-supplied function or table used by this function must
- + be optional: if the application does not supply it, the square
- + root function must still compute square roots.)
- +
- +These requirements apply to the modified work as a whole. If
- +identifiable sections of that work are not derived from the Library,
- +and can be reasonably considered independent and separate works in
- +themselves, then this License, and its terms, do not apply to those
- +sections when you distribute them as separate works. But when you
- +distribute the same sections as part of a whole which is a work based
- +on the Library, the distribution of the whole must be on the terms of
- +this License, whose permissions for other licensees extend to the
- +entire whole, and thus to each and every part regardless of who wrote
- +it.
- +
- +Thus, it is not the intent of this section to claim rights or contest
- +your rights to work written entirely by you; rather, the intent is to
- +exercise the right to control the distribution of derivative or
- +collective works based on the Library.
- +
- +In addition, mere aggregation of another work not based on the Library
- +with the Library (or with a work based on the Library) on a volume of
- +a storage or distribution medium does not bring the other work under
- +the scope of this License.
- +
- + 3. You may opt to apply the terms of the ordinary GNU General Public
- +License instead of this License to a given copy of the Library. To do
- +this, you must alter all the notices that refer to this License, so
- +that they refer to the ordinary GNU General Public License, version 2,
- +instead of to this License. (If a newer version than version 2 of the
- +ordinary GNU General Public License has appeared, then you can specify
- +that version instead if you wish.) Do not make any other change in
- +these notices.
- +
- + Once this change is made in a given copy, it is irreversible for
- +that copy, so the ordinary GNU General Public License applies to all
- +subsequent copies and derivative works made from that copy.
- +
- + This option is useful when you wish to copy part of the code of
- +the Library into a program that is not a library.
- +
- + 4. You may copy and distribute the Library (or a portion or
- +derivative of it, under Section 2) in object code or executable form
- +under the terms of Sections 1 and 2 above provided that you accompany
- +it with the complete corresponding machine-readable source code, which
- +must be distributed under the terms of Sections 1 and 2 above on a
- +medium customarily used for software interchange.
- +
- + If distribution of object code is made by offering access to copy
- +from a designated place, then offering equivalent access to copy the
- +source code from the same place satisfies the requirement to
- +distribute the source code, even though third parties are not
- +compelled to copy the source along with the object code.
- +
- + 5. A program that contains no derivative of any portion of the
- +Library, but is designed to work with the Library by being compiled or
- +linked with it, is called a "work that uses the Library". Such a
- +work, in isolation, is not a derivative work of the Library, and
- +therefore falls outside the scope of this License.
- +
- + However, linking a "work that uses the Library" with the Library
- +creates an executable that is a derivative of the Library (because it
- +contains portions of the Library), rather than a "work that uses the
- +library". The executable is therefore covered by this License.
- +Section 6 states terms for distribution of such executables.
- +
- + When a "work that uses the Library" uses material from a header file
- +that is part of the Library, the object code for the work may be a
- +derivative work of the Library even though the source code is not.
- +Whether this is true is especially significant if the work can be
- +linked without the Library, or if the work is itself a library. The
- +threshold for this to be true is not precisely defined by law.
- +
- + If such an object file uses only numerical parameters, data
- +structure layouts and accessors, and small macros and small inline
- +functions (ten lines or less in length), then the use of the object
- +file is unrestricted, regardless of whether it is legally a derivative
- +work. (Executables containing this object code plus portions of the
- +Library will still fall under Section 6.)
- +
- + Otherwise, if the work is a derivative of the Library, you may
- +distribute the object code for the work under the terms of Section 6.
- +Any executables containing that work also fall under Section 6,
- +whether or not they are linked directly with the Library itself.
- +
- + 6. As an exception to the Sections above, you may also combine or
- +link a "work that uses the Library" with the Library to produce a
- +work containing portions of the Library, and distribute that work
- +under terms of your choice, provided that the terms permit
- +modification of the work for the customer's own use and reverse
- +engineering for debugging such modifications.
- +
- + You must give prominent notice with each copy of the work that the
- +Library is used in it and that the Library and its use are covered by
- +this License. You must supply a copy of this License. If the work
- +during execution displays copyright notices, you must include the
- +copyright notice for the Library among them, as well as a reference
- +directing the user to the copy of this License. Also, you must do one
- +of these things:
- +
- + a) Accompany the work with the complete corresponding
- + machine-readable source code for the Library including whatever
- + changes were used in the work (which must be distributed under
- + Sections 1 and 2 above); and, if the work is an executable linked
- + with the Library, with the complete machine-readable "work that
- + uses the Library", as object code and/or source code, so that the
- + user can modify the Library and then relink to produce a modified
- + executable containing the modified Library. (It is understood
- + that the user who changes the contents of definitions files in the
- + Library will not necessarily be able to recompile the application
- + to use the modified definitions.)
- +
- + b) Use a suitable shared library mechanism for linking with the
- + Library. A suitable mechanism is one that (1) uses at run time a
- + copy of the library already present on the user's computer system,
- + rather than copying library functions into the executable, and (2)
- + will operate properly with a modified version of the library, if
- + the user installs one, as long as the modified version is
- + interface-compatible with the version that the work was made with.
- +
- + c) Accompany the work with a written offer, valid for at
- + least three years, to give the same user the materials
- + specified in Subsection 6a, above, for a charge no more
- + than the cost of performing this distribution.
- +
- + d) If distribution of the work is made by offering access to copy
- + from a designated place, offer equivalent access to copy the above
- + specified materials from the same place.
- +
- + e) Verify that the user has already received a copy of these
- + materials or that you have already sent this user a copy.
- +
- + For an executable, the required form of the "work that uses the
- +Library" must include any data and utility programs needed for
- +reproducing the executable from it. However, as a special exception,
- +the materials to be distributed need not include anything that is
- +normally distributed (in either source or binary form) with the major
- +components (compiler, kernel, and so on) of the operating system on
- +which the executable runs, unless that component itself accompanies
- +the executable.
- +
- + It may happen that this requirement contradicts the license
- +restrictions of other proprietary libraries that do not normally
- +accompany the operating system. Such a contradiction means you cannot
- +use both them and the Library together in an executable that you
- +distribute.
- +
- + 7. You may place library facilities that are a work based on the
- +Library side-by-side in a single library together with other library
- +facilities not covered by this License, and distribute such a combined
- +library, provided that the separate distribution of the work based on
- +the Library and of the other library facilities is otherwise
- +permitted, and provided that you do these two things:
- +
- + a) Accompany the combined library with a copy of the same work
- + based on the Library, uncombined with any other library
- + facilities. This must be distributed under the terms of the
- + Sections above.
- +
- + b) Give prominent notice with the combined library of the fact
- + that part of it is a work based on the Library, and explaining
- + where to find the accompanying uncombined form of the same work.
- +
- + 8. You may not copy, modify, sublicense, link with, or distribute
- +the Library except as expressly provided under this License. Any
- +attempt otherwise to copy, modify, sublicense, link with, or
- +distribute the Library is void, and will automatically terminate your
- +rights under this License. However, parties who have received copies,
- +or rights, from you under this License will not have their licenses
- +terminated so long as such parties remain in full compliance.
- +
- + 9. You are not required to accept this License, since you have not
- +signed it. However, nothing else grants you permission to modify or
- +distribute the Library or its derivative works. These actions are
- +prohibited by law if you do not accept this License. Therefore, by
- +modifying or distributing the Library (or any work based on the
- +Library), you indicate your acceptance of this License to do so, and
- +all its terms and conditions for copying, distributing or modifying
- +the Library or works based on it.
- +
- + 10. Each time you redistribute the Library (or any work based on the
- +Library), the recipient automatically receives a license from the
- +original licensor to copy, distribute, link with or modify the Library
- +subject to these terms and conditions. You may not impose any further
- +restrictions on the recipients' exercise of the rights granted herein.
- +You are not responsible for enforcing compliance by third parties with
- +this License.
- +
- + 11. If, as a consequence of a court judgment or allegation of patent
- +infringement or for any other reason (not limited to patent issues),
- +conditions are imposed on you (whether by court order, agreement or
- +otherwise) that contradict the conditions of this License, they do not
- +excuse you from the conditions of this License. If you cannot
- +distribute so as to satisfy simultaneously your obligations under this
- +License and any other pertinent obligations, then as a consequence you
- +may not distribute the Library at all. For example, if a patent
- +license would not permit royalty-free redistribution of the Library by
- +all those who receive copies directly or indirectly through you, then
- +the only way you could satisfy both it and this License would be to
- +refrain entirely from distribution of the Library.
- +
- +If any portion of this section is held invalid or unenforceable under any
- +particular circumstance, the balance of the section is intended to apply,
- +and the section as a whole is intended to apply in other circumstances.
- +
- +It is not the purpose of this section to induce you to infringe any
- +patents or other property right claims or to contest validity of any
- +such claims; this section has the sole purpose of protecting the
- +integrity of the free software distribution system which is
- +implemented by public license practices. Many people have made
- +generous contributions to the wide range of software distributed
- +through that system in reliance on consistent application of that
- +system; it is up to the author/donor to decide if he or she is willing
- +to distribute software through any other system and a licensee cannot
- +impose that choice.
- +
- +This section is intended to make thoroughly clear what is believed to
- +be a consequence of the rest of this License.
- +
- + 12. If the distribution and/or use of the Library is restricted in
- +certain countries either by patents or by copyrighted interfaces, the
- +original copyright holder who places the Library under this License may add
- +an explicit geographical distribution limitation excluding those countries,
- +so that distribution is permitted only in or among countries not thus
- +excluded. In such case, this License incorporates the limitation as if
- +written in the body of this License.
- +
- + 13. The Free Software Foundation may publish revised and/or new
- +versions of the Lesser General Public License from time to time.
- +Such new versions will be similar in spirit to the present version,
- +but may differ in detail to address new problems or concerns.
- +
- +Each version is given a distinguishing version number. If the Library
- +specifies a version number of this License which applies to it and
- +"any later version", you have the option of following the terms and
- +conditions either of that version or of any later version published by
- +the Free Software Foundation. If the Library does not specify a
- +license version number, you may choose any version ever published by
- +the Free Software Foundation.
- +
- + 14. If you wish to incorporate parts of the Library into other free
- +programs whose distribution conditions are incompatible with these,
- +write to the author to ask for permission. For software which is
- +copyrighted by the Free Software Foundation, write to the Free
- +Software Foundation; we sometimes make exceptions for this. Our
- +decision will be guided by the two goals of preserving the free status
- +of all derivatives of our free software and of promoting the sharing
- +and reuse of software generally.
- +
- + NO WARRANTY
- +
- + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
- +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
- +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
- +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
- +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
- +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
- +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
- +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
- +
- + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
- +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
- +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
- +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
- +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
- +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
- +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
- +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
- +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
- +DAMAGES.
- +
- + END OF TERMS AND CONDITIONS
- +
- + How to Apply These Terms to Your New Libraries
- +
- + If you develop a new library, and you want it to be of the greatest
- +possible use to the public, we recommend making it free software that
- +everyone can redistribute and change. You can do so by permitting
- +redistribution under these terms (or, alternatively, under the terms of the
- +ordinary General Public License).
- +
- + To apply these terms, attach the following notices to the library. It is
- +safest to attach them to the start of each source file to most effectively
- +convey the exclusion of warranty; and each file should have at least the
- +"copyright" line and a pointer to where the full notice is found.
- +
- + <one line to give the library's name and a brief idea of what it does.>
- + Copyright (C) <year> <name of author>
- +
- + This library is free software; you can redistribute it and/or
- + modify it under the terms of the GNU Lesser General Public
- + License as published by the Free Software Foundation; either
- + version 2.1 of the License, or (at your option) any later version.
- +
- + This library 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
- + Lesser General Public License for more details.
- +
- + You should have received a copy of the GNU Lesser General Public
- + License along with this library; if not, write to the Free Software
- + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- +
- +Also add information on how to contact you by electronic and paper mail.
- +
- +You should also get your employer (if you work as a programmer) or your
- +school, if any, to sign a "copyright disclaimer" for the library, if
- +necessary. Here is a sample; alter the names:
- +
- + Yoyodyne, Inc., hereby disclaims all copyright interest in the
- + library `Frob' (a library for tweaking knobs) written by James Random Hacker.
- +
- + <signature of Ty Coon>, 1 April 1990
- + Ty Coon, President of Vice
- +
- +That's all there is to it!
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/.git flatpak-builder-0.10.6/libglnx/.git
- --- flatpak-builder-0.10.6.orig/libglnx/.git 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/.git 2018-02-11 12:03:43.426373306 +0300
- @@ -0,0 +1 @@
- +gitdir: ../.git/modules/libglnx
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/.gitignore flatpak-builder-0.10.6/libglnx/.gitignore
- --- flatpak-builder-0.10.6.orig/libglnx/.gitignore 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/.gitignore 2018-02-11 12:03:43.447373307 +0300
- @@ -0,0 +1,16 @@
- +# A path ostree writes to work around automake bug with
- +# subdir-objects
- +Makefile-libglnx.am.inc
- +
- +# Some standard bits
- +.deps
- +.libs
- +.dirstamp
- +*.typelib
- +*.la
- +*.lo
- +*.o
- +*.pyc
- +*.stamp
- +*~
- +
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-backport-autocleanups.h flatpak-builder-0.10.6/libglnx/glnx-backport-autocleanups.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-backport-autocleanups.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-backport-autocleanups.h 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,124 @@
- +/*
- + * Copyright © 2015 Canonical Limited
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the licence, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, see <http://www.gnu.org/licenses/>.
- + *
- + * Author: Ryan Lortie <desrt@desrt.ca>
- + */
- +
- +#pragma once
- +
- +#include <glnx-backport-autoptr.h>
- +
- +#if !GLIB_CHECK_VERSION(2, 43, 4)
- +
- +static inline void
- +g_autoptr_cleanup_generic_gfree (void *p)
- +{
- + void **pp = (void**)p;
- + if (*pp)
- + g_free (*pp);
- +}
- +
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GAsyncQueue, g_async_queue_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBookmarkFile, g_bookmark_file_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBytes, g_bytes_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GChecksum, g_checksum_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDateTime, g_date_time_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDir, g_dir_close)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GError, g_error_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHashTable, g_hash_table_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHmac, g_hmac_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GIOChannel, g_io_channel_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GKeyFile, g_key_file_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GList, g_list_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GArray, g_array_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPtrArray, g_ptr_array_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainContext, g_main_context_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainLoop, g_main_loop_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSource, g_source_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMappedFile, g_mapped_file_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMarkupParseContext, g_markup_parse_context_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(gchar, g_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GNode, g_node_destroy)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionContext, g_option_context_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionGroup, g_option_group_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPatternSpec, g_pattern_spec_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GQueue, g_queue_free)
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GQueue, g_queue_clear)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRand, g_rand_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRegex, g_regex_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMatchInfo, g_match_info_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GScanner, g_scanner_destroy)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSequence, g_sequence_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSList, g_slist_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GStringChunk, g_string_chunk_free)
- +G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GThread, g_thread_unref)
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GMutex, g_mutex_clear)
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GCond, g_cond_clear)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimer, g_timer_destroy)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimeZone, g_time_zone_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTree, g_tree_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariant, g_variant_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantBuilder, g_variant_builder_unref)
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantBuilder, g_variant_builder_clear)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantIter, g_variant_iter_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantDict, g_variant_dict_unref)
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantDict, g_variant_dict_clear)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantType, g_variant_type_free)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSubprocess, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSubprocessLauncher, g_object_unref)
- +
- +/* Add GObject-based types as needed. */
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GCancellable, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GConverter, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GConverterOutputStream, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDataInputStream, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFile, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileEnumerator, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileIOStream, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileInfo, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileInputStream, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileMonitor, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileOutputStream, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GInputStream, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMemoryInputStream, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMemoryOutputStream, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOutputStream, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSocket, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSocketAddress, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTask, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTlsCertificate, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTlsDatabase, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTlsInteraction, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDBusConnection, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDBusMessage, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GZlibCompressor, g_object_unref)
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GZlibDecompressor, g_object_unref)
- +
- +#endif
- +
- +#if !GLIB_CHECK_VERSION(2, 45, 8)
- +
- +static inline void
- +g_autoptr_cleanup_gstring_free (GString *string)
- +{
- + if (string)
- + g_string_free (string, TRUE);
- +}
- +
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GString, g_autoptr_cleanup_gstring_free)
- +
- +#endif
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-backport-autoptr.h flatpak-builder-0.10.6/libglnx/glnx-backport-autoptr.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-backport-autoptr.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-backport-autoptr.h 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,133 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2015 Colin Walters <walters@verbum.org>
- + *
- + * GLIB - Library of useful routines for C programming
- + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <gio/gio.h>
- +
- +G_BEGIN_DECLS
- +
- +#if !GLIB_CHECK_VERSION(2, 43, 4)
- +
- +#define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
- +#define _GLIB_AUTOPTR_TYPENAME(TypeName) TypeName##_autoptr
- +#define _GLIB_AUTO_FUNC_NAME(TypeName) glib_auto_cleanup_##TypeName
- +#define _GLIB_CLEANUP(func) __attribute__((cleanup(func)))
- +#define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \
- + typedef ModuleObjName *_GLIB_AUTOPTR_TYPENAME(ModuleObjName); \
- + static inline void _GLIB_AUTOPTR_FUNC_NAME(ModuleObjName) (ModuleObjName **_ptr) { \
- + _GLIB_AUTOPTR_FUNC_NAME(ParentName) ((ParentName **) _ptr); } \
- +
- +
- +/* these macros are API */
- +#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
- + typedef TypeName *_GLIB_AUTOPTR_TYPENAME(TypeName); \
- + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
- + static inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) { if (*_ptr) (func) (*_ptr); } \
- + G_GNUC_END_IGNORE_DEPRECATIONS
- +#define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func) \
- + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
- + static inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { (func) (_ptr); } \
- + G_GNUC_END_IGNORE_DEPRECATIONS
- +#define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none) \
- + G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
- + static inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { if (*_ptr != none) (func) (*_ptr); } \
- + G_GNUC_END_IGNORE_DEPRECATIONS
- +#define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName)
- +#define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName
- +#define g_autofree _GLIB_CLEANUP(g_autoptr_cleanup_generic_gfree)
- +
- +/**
- + * g_steal_pointer:
- + * @pp: a pointer to a pointer
- + *
- + * Sets @pp to %NULL, returning the value that was there before.
- + *
- + * Conceptually, this transfers the ownership of the pointer from the
- + * referenced variable to the "caller" of the macro (ie: "steals" the
- + * reference).
- + *
- + * The return value will be properly typed, according to the type of
- + * @pp.
- + *
- + * This can be very useful when combined with g_autoptr() to prevent the
- + * return value of a function from being automatically freed. Consider
- + * the following example (which only works on GCC and clang):
- + *
- + * |[
- + * GObject *
- + * create_object (void)
- + * {
- + * g_autoptr(GObject) obj = g_object_new (G_TYPE_OBJECT, NULL);
- + *
- + * if (early_error_case)
- + * return NULL;
- + *
- + * return g_steal_pointer (&obj);
- + * }
- + * ]|
- + *
- + * It can also be used in similar ways for 'out' parameters and is
- + * particularly useful for dealing with optional out parameters:
- + *
- + * |[
- + * gboolean
- + * get_object (GObject **obj_out)
- + * {
- + * g_autoptr(GObject) obj = g_object_new (G_TYPE_OBJECT, NULL);
- + *
- + * if (early_error_case)
- + * return FALSE;
- + *
- + * if (obj_out)
- + * *obj_out = g_steal_pointer (&obj);
- + *
- + * return TRUE;
- + * }
- + * ]|
- + *
- + * In the above example, the object will be automatically freed in the
- + * early error case and also in the case that %NULL was given for
- + * @obj_out.
- + *
- + * Since: 2.44
- + */
- +static inline gpointer
- +(g_steal_pointer) (gpointer pp)
- +{
- + gpointer *ptr = (gpointer *) pp;
- + gpointer ref;
- +
- + ref = *ptr;
- + *ptr = NULL;
- +
- + return ref;
- +}
- +
- +/* type safety */
- +#define g_steal_pointer(pp) \
- + (0 ? (*(pp)) : (g_steal_pointer) (pp))
- +
- +#endif /* !GLIB_CHECK_VERSION(2, 43, 3) */
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-backports.c flatpak-builder-0.10.6/libglnx/glnx-backports.c
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-backports.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-backports.c 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,61 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2015 Colin Walters <walters@verbum.org>
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU Lesser General Public License as published
- + * by the Free Software Foundation; either version 2 of the licence or (at
- + * your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General
- + * Public License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +
- +#include "glnx-backports.h"
- +
- +#if !GLIB_CHECK_VERSION(2, 44, 0)
- +gboolean
- +glnx_strv_contains (const gchar * const *strv,
- + const gchar *str)
- +{
- + g_return_val_if_fail (strv != NULL, FALSE);
- + g_return_val_if_fail (str != NULL, FALSE);
- +
- + for (; *strv != NULL; strv++)
- + {
- + if (g_str_equal (str, *strv))
- + return TRUE;
- + }
- +
- + return FALSE;
- +}
- +
- +gboolean
- +glnx_set_object (GObject **object_ptr,
- + GObject *new_object)
- +{
- + GObject *old_object = *object_ptr;
- +
- + if (old_object == new_object)
- + return FALSE;
- +
- + if (new_object != NULL)
- + g_object_ref (new_object);
- +
- + *object_ptr = new_object;
- +
- + if (old_object != NULL)
- + g_object_unref (old_object);
- +
- + return TRUE;
- +}
- +#endif
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-backports.h flatpak-builder-0.10.6/libglnx/glnx-backports.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-backports.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-backports.h 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,46 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2015 Colin Walters <walters@verbum.org>
- + *
- + * GLIB - Library of useful routines for C programming
- + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <gio/gio.h>
- +
- +G_BEGIN_DECLS
- +
- +#if !GLIB_CHECK_VERSION(2, 44, 0)
- +
- +#define g_strv_contains glnx_strv_contains
- +gboolean glnx_strv_contains (const gchar * const *strv,
- + const gchar *str);
- +
- +#define g_set_object(object_ptr, new_object) \
- + (/* Check types match. */ \
- + 0 ? *(object_ptr) = (new_object), FALSE : \
- + glnx_set_object ((GObject **) (object_ptr), (GObject *) (new_object)) \
- + )
- +gboolean glnx_set_object (GObject **object_ptr,
- + GObject *new_object);
- +
- +#endif /* !GLIB_CHECK_VERSION(2, 44, 0) */
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-console.c flatpak-builder-0.10.6/libglnx/glnx-console.c
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-console.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-console.c 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,309 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2013,2014,2015 Colin Walters <walters@verbum.org>
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU Lesser General Public License as published
- + * by the Free Software Foundation; either version 2 of the licence or (at
- + * your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General
- + * Public License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +
- +#include "glnx-console.h"
- +
- +#include <unistd.h>
- +#include <string.h>
- +#include <fcntl.h>
- +#include <stdio.h>
- +#include <errno.h>
- +#include <sys/ioctl.h>
- +
- +static char *current_text = NULL;
- +static gint current_percent = -1;
- +static gboolean locked;
- +
- +static gboolean
- +stdout_is_tty (void)
- +{
- + static gsize initialized = 0;
- + static gboolean stdout_is_tty_v;
- +
- + if (g_once_init_enter (&initialized))
- + {
- + stdout_is_tty_v = isatty (1);
- + g_once_init_leave (&initialized, 1);
- + }
- +
- + return stdout_is_tty_v;
- +}
- +
- +static volatile guint cached_columns = 0;
- +static volatile guint cached_lines = 0;
- +
- +static int
- +fd_columns (int fd)
- +{
- + struct winsize ws = {};
- +
- + if (ioctl (fd, TIOCGWINSZ, &ws) < 0)
- + return -errno;
- +
- + if (ws.ws_col <= 0)
- + return -EIO;
- +
- + return ws.ws_col;
- +}
- +
- +/**
- + * glnx_console_columns:
- + *
- + * Returns: The number of columns for terminal output
- + */
- +guint
- +glnx_console_columns (void)
- +{
- + if (G_UNLIKELY (cached_columns == 0))
- + {
- + int c;
- +
- + c = fd_columns (STDOUT_FILENO);
- +
- + if (c <= 0)
- + c = 80;
- +
- + if (c > 256)
- + c = 256;
- +
- + cached_columns = c;
- + }
- +
- + return cached_columns;
- +}
- +
- +static int
- +fd_lines (int fd)
- +{
- + struct winsize ws = {};
- +
- + if (ioctl (fd, TIOCGWINSZ, &ws) < 0)
- + return -errno;
- +
- + if (ws.ws_row <= 0)
- + return -EIO;
- +
- + return ws.ws_row;
- +}
- +
- +/**
- + * glnx_console_lines:
- + *
- + * Returns: The number of lines for terminal output
- + */
- +guint
- +glnx_console_lines (void)
- +{
- + if (G_UNLIKELY (cached_lines == 0))
- + {
- + int l;
- +
- + l = fd_lines (STDOUT_FILENO);
- +
- + if (l <= 0)
- + l = 24;
- +
- + cached_lines = l;
- + }
- +
- + return cached_lines;
- +}
- +
- +static void
- +on_sigwinch (int signum)
- +{
- + cached_columns = 0;
- + cached_lines = 0;
- +}
- +
- +void
- +glnx_console_lock (GLnxConsoleRef *console)
- +{
- + static gsize sigwinch_initialized = 0;
- +
- + g_return_if_fail (!locked);
- + g_return_if_fail (!console->locked);
- +
- + console->is_tty = stdout_is_tty ();
- +
- + locked = console->locked = TRUE;
- +
- + current_percent = 0;
- +
- + if (console->is_tty)
- + {
- + if (g_once_init_enter (&sigwinch_initialized))
- + {
- + signal (SIGWINCH, on_sigwinch);
- + g_once_init_leave (&sigwinch_initialized, 1);
- + }
- +
- + { static const char initbuf[] = { '\n', 0x1B, 0x37 };
- + (void) fwrite (initbuf, 1, sizeof (initbuf), stdout);
- + }
- + }
- +}
- +
- +static void
- +printpad (const char *padbuf,
- + guint padbuf_len,
- + guint n)
- +{
- + const guint d = n / padbuf_len;
- + const guint r = n % padbuf_len;
- + guint i;
- +
- + for (i = 0; i < d; i++)
- + fwrite (padbuf, 1, padbuf_len, stdout);
- + fwrite (padbuf, 1, r, stdout);
- +}
- +
- +static void
- +text_percent_internal (const char *text,
- + int percentage)
- +{
- + static const char equals[] = "====================";
- + const guint n_equals = sizeof (equals) - 1;
- + static const char spaces[] = " ";
- + const guint n_spaces = sizeof (spaces) - 1;
- + const guint ncolumns = glnx_console_columns ();
- + const guint bar_min = 10;
- +
- + if (text && !*text)
- + text = NULL;
- +
- + const guint input_textlen = text ? strlen (text) : 0;
- +
- + if (percentage == current_percent
- + && g_strcmp0 (text, current_text) == 0)
- + return;
- +
- + if (!stdout_is_tty ())
- + {
- + if (text)
- + fprintf (stdout, "%s", text);
- + if (percentage != -1)
- + {
- + if (text)
- + fputc (' ', stdout);
- + fprintf (stdout, "%u%%", percentage);
- + }
- + fputc ('\n', stdout);
- + fflush (stdout);
- + return;
- + }
- +
- + if (ncolumns < bar_min)
- + return; /* TODO: spinner */
- +
- + /* Restore cursor */
- + { const char beginbuf[2] = { 0x1B, 0x38 };
- + (void) fwrite (beginbuf, 1, sizeof (beginbuf), stdout);
- + }
- +
- + if (percentage == -1)
- + {
- + if (text != NULL)
- + fwrite (text, 1, input_textlen, stdout);
- +
- + /* Overwrite remaining space, if any */
- + if (ncolumns > input_textlen)
- + printpad (spaces, n_spaces, ncolumns - input_textlen);
- + }
- + else
- + {
- + const guint textlen = MIN (input_textlen, ncolumns - bar_min);
- + const guint barlen = ncolumns - (textlen + 1);;
- +
- + if (textlen > 0)
- + {
- + fwrite (text, 1, textlen, stdout);
- + fputc (' ', stdout);
- + }
- +
- + {
- + const guint nbraces = 2;
- + const guint textpercent_len = 5;
- + const guint bar_internal_len = barlen - nbraces - textpercent_len;
- + const guint eqlen = bar_internal_len * (percentage / 100.0);
- + const guint spacelen = bar_internal_len - eqlen;
- +
- + fputc ('[', stdout);
- + printpad (equals, n_equals, eqlen);
- + printpad (spaces, n_spaces, spacelen);
- + fputc (']', stdout);
- + fprintf (stdout, " %3d%%", percentage);
- + }
- + }
- +
- + fflush (stdout);
- +}
- +
- +/**
- + * glnx_console_progress_text_percent:
- + * @text: Show this text before the progress bar
- + * @percentage: An integer in the range of 0 to 100
- + *
- + * On a tty, print to the console @text followed by an ASCII art
- + * progress bar whose percentage is @percentage. If stdout is not a
- + * tty, a more basic line by line change will be printed.
- + *
- + * You must have called glnx_console_lock() before invoking this
- + * function.
- + *
- + */
- +void
- +glnx_console_progress_text_percent (const char *text,
- + guint percentage)
- +{
- + g_return_if_fail (percentage <= 100);
- +
- + text_percent_internal (text, percentage);
- +}
- +
- +void
- +glnx_console_text (const char *text)
- +{
- + text_percent_internal (text, -1);
- +}
- +
- +/**
- + * glnx_console_unlock:
- + *
- + * Print a newline, and reset all cached console progress state.
- + *
- + * This function does nothing if stdout is not a tty.
- + */
- +void
- +glnx_console_unlock (GLnxConsoleRef *console)
- +{
- + g_return_if_fail (locked);
- + g_return_if_fail (console->locked);
- +
- + current_percent = -1;
- + g_clear_pointer (¤t_text, g_free);
- +
- + if (console->is_tty)
- + fputc ('\n', stdout);
- +
- + locked = console->locked = FALSE;
- +}
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-console.h flatpak-builder-0.10.6/libglnx/glnx-console.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-console.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-console.h 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,55 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2013,2014,2015 Colin Walters <walters@verbum.org>
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU Lesser General Public License as published
- + * by the Free Software Foundation; either version 2 of the licence or (at
- + * your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General
- + * Public License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <glnx-backport-autocleanups.h>
- +
- +G_BEGIN_DECLS
- +
- +struct GLnxConsoleRef {
- + gboolean locked;
- + gboolean is_tty;
- +};
- +
- +typedef struct GLnxConsoleRef GLnxConsoleRef;
- +
- +void glnx_console_lock (GLnxConsoleRef *ref);
- +
- +void glnx_console_text (const char *text);
- +
- +void glnx_console_progress_text_percent (const char *text,
- + guint percentage);
- +
- +void glnx_console_unlock (GLnxConsoleRef *ref);
- +
- +guint glnx_console_lines (void);
- +
- +guint glnx_console_columns (void);
- +
- +static inline void
- +glnx_console_ref_cleanup (GLnxConsoleRef *p)
- +{
- + if (p->locked)
- + glnx_console_unlock (p);
- +}
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxConsoleRef, glnx_console_ref_cleanup)
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-dirfd.c flatpak-builder-0.10.6/libglnx/glnx-dirfd.c
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-dirfd.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-dirfd.c 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,390 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +
- +#include <string.h>
- +
- +#include <glnx-dirfd.h>
- +#include <glnx-errors.h>
- +#include <glnx-local-alloc.h>
- +
- +/**
- + * glnx_opendirat_with_errno:
- + * @dfd: File descriptor for origin directory
- + * @name: Pathname, relative to @dfd
- + * @follow: Whether or not to follow symbolic links
- + *
- + * Use openat() to open a directory, using a standard set of flags.
- + * This function sets errno.
- + */
- +int
- +glnx_opendirat_with_errno (int dfd,
- + const char *path,
- + gboolean follow)
- +{
- + int flags = O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOCTTY;
- + if (!follow)
- + flags |= O_NOFOLLOW;
- +
- + dfd = glnx_dirfd_canonicalize (dfd);
- +
- + return openat (dfd, path, flags);
- +}
- +
- +/**
- + * glnx_opendirat:
- + * @dfd: File descriptor for origin directory
- + * @path: Pathname, relative to @dfd
- + * @follow: Whether or not to follow symbolic links
- + * @error: Error
- + *
- + * Use openat() to open a directory, using a standard set of flags.
- + */
- +gboolean
- +glnx_opendirat (int dfd,
- + const char *path,
- + gboolean follow,
- + int *out_fd,
- + GError **error)
- +{
- + int ret = glnx_opendirat_with_errno (dfd, path, follow);
- + if (ret == -1)
- + return glnx_throw_errno_prefix (error, "opendir(%s)", path);
- + *out_fd = ret;
- + return TRUE;
- +}
- +
- +struct GLnxRealDirfdIterator
- +{
- + gboolean initialized;
- + int fd;
- + DIR *d;
- +};
- +typedef struct GLnxRealDirfdIterator GLnxRealDirfdIterator;
- +
- +/**
- + * glnx_dirfd_iterator_init_at:
- + * @dfd: File descriptor, may be AT_FDCWD or -1
- + * @path: Path, may be relative to @dfd
- + * @follow: If %TRUE and the last component of @path is a symlink, follow it
- + * @out_dfd_iter: (out caller-allocates): A directory iterator, will be initialized
- + * @error: Error
- + *
- + * Initialize @out_dfd_iter from @dfd and @path.
- + */
- +gboolean
- +glnx_dirfd_iterator_init_at (int dfd,
- + const char *path,
- + gboolean follow,
- + GLnxDirFdIterator *out_dfd_iter,
- + GError **error)
- +{
- + glnx_fd_close int fd = -1;
- + if (!glnx_opendirat (dfd, path, follow, &fd, error))
- + return FALSE;
- +
- + if (!glnx_dirfd_iterator_init_take_fd (&fd, out_dfd_iter, error))
- + return FALSE;
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_dirfd_iterator_init_take_fd:
- + * @dfd: File descriptor - ownership is taken, and the value is set to -1
- + * @dfd_iter: A directory iterator
- + * @error: Error
- + *
- + * Steal ownership of @dfd, using it to initialize @dfd_iter for
- + * iteration.
- + */
- +gboolean
- +glnx_dirfd_iterator_init_take_fd (int *dfd,
- + GLnxDirFdIterator *dfd_iter,
- + GError **error)
- +{
- + GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter;
- + DIR *d = fdopendir (*dfd);
- + if (!d)
- + return glnx_throw_errno_prefix (error, "fdopendir");
- +
- + real_dfd_iter->fd = glnx_steal_fd (dfd);
- + real_dfd_iter->d = d;
- + real_dfd_iter->initialized = TRUE;
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_dirfd_iterator_next_dent:
- + * @dfd_iter: A directory iterator
- + * @out_dent: (out) (transfer none): Pointer to dirent; do not free
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Read the next value from @dfd_iter, causing @out_dent to be
- + * updated. If end of stream is reached, @out_dent will be set
- + * to %NULL, and %TRUE will be returned.
- + */
- +gboolean
- +glnx_dirfd_iterator_next_dent (GLnxDirFdIterator *dfd_iter,
- + struct dirent **out_dent,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter;
- +
- + g_return_val_if_fail (out_dent, FALSE);
- + g_return_val_if_fail (dfd_iter->initialized, FALSE);
- +
- + if (g_cancellable_set_error_if_cancelled (cancellable, error))
- + return FALSE;
- +
- + do
- + {
- + errno = 0;
- + *out_dent = readdir (real_dfd_iter->d);
- + if (*out_dent == NULL && errno != 0)
- + return glnx_throw_errno_prefix (error, "readdir");
- + } while (*out_dent &&
- + (strcmp ((*out_dent)->d_name, ".") == 0 ||
- + strcmp ((*out_dent)->d_name, "..") == 0));
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_dirfd_iterator_next_dent_ensure_dtype:
- + * @dfd_iter: A directory iterator
- + * @out_dent: (out) (transfer none): Pointer to dirent; do not free
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * A variant of @glnx_dirfd_iterator_next_dent, which will ensure the
- + * `dent->d_type` member is filled in by calling `fstatat`
- + * automatically if the underlying filesystem type sets `DT_UNKNOWN`.
- + */
- +gboolean
- +glnx_dirfd_iterator_next_dent_ensure_dtype (GLnxDirFdIterator *dfd_iter,
- + struct dirent **out_dent,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + struct dirent *ret_dent;
- +
- + g_return_val_if_fail (out_dent, FALSE);
- +
- + if (!glnx_dirfd_iterator_next_dent (dfd_iter, out_dent, cancellable, error))
- + return FALSE;
- +
- + ret_dent = *out_dent;
- +
- + if (ret_dent)
- + {
- +
- + if (ret_dent->d_type == DT_UNKNOWN)
- + {
- + struct stat stbuf;
- + if (TEMP_FAILURE_RETRY (fstatat (dfd_iter->fd, ret_dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW)) != 0)
- + return glnx_throw_errno (error);
- + ret_dent->d_type = IFTODT (stbuf.st_mode);
- + }
- + }
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_dirfd_iterator_clear:
- + * @dfd_iter: Iterator, will be de-initialized
- + *
- + * Unset @dfd_iter, freeing any resources. If @dfd_iter is not
- + * initialized, do nothing.
- + */
- +void
- +glnx_dirfd_iterator_clear (GLnxDirFdIterator *dfd_iter)
- +{
- + GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter;
- + /* fd is owned by dfd_iter */
- + if (!real_dfd_iter->initialized)
- + return;
- + (void) closedir (real_dfd_iter->d);
- + real_dfd_iter->initialized = FALSE;
- +}
- +
- +/**
- + * glnx_fdrel_abspath:
- + * @dfd: Directory fd
- + * @path: Path
- + *
- + * Turn a fd-relative pair into something that can be used for legacy
- + * APIs expecting absolute paths.
- + *
- + * This is Linux specific, and only valid inside this process (unless
- + * you set up the child process to have the exact same fd number, but
- + * don't try that).
- + */
- +char *
- +glnx_fdrel_abspath (int dfd,
- + const char *path)
- +{
- + dfd = glnx_dirfd_canonicalize (dfd);
- + if (dfd == AT_FDCWD)
- + return g_strdup (path);
- + return g_strdup_printf ("/proc/self/fd/%d/%s", dfd, path);
- +}
- +
- +/**
- + * glnx_gen_temp_name:
- + * @tmpl: (type filename): template directory name, the last 6 characters will be replaced
- + *
- + * Replace the last 6 characters of @tmpl with random ASCII. You must
- + * use this in combination with a mechanism to ensure race-free file
- + * creation such as `O_EXCL`.
- + */
- +void
- +glnx_gen_temp_name (gchar *tmpl)
- +{
- + size_t len;
- + char *XXXXXX;
- + int i;
- + static const char letters[] =
- + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- + static const int NLETTERS = sizeof (letters) - 1;
- +
- + g_return_if_fail (tmpl != NULL);
- + len = strlen (tmpl);
- + g_return_if_fail (len >= 6);
- +
- + XXXXXX = tmpl + (len - 6);
- +
- + for (i = 0; i < 6; i++)
- + XXXXXX[i] = letters[g_random_int_range(0, NLETTERS)];
- +}
- +
- +/**
- + * glnx_mkdtempat:
- + * @dfd: Directory fd
- + * @tmpl: (type filename): template directory name, last 6 characters will be replaced
- + * @mode: permissions to create the temporary directory with
- + * @error: Error
- + *
- + * Similar to g_mkdtemp_full, but using openat.
- + */
- +gboolean
- +glnx_mkdtempat (int dfd,
- + gchar *tmpl,
- + int mode,
- + GError **error)
- +{
- + int count;
- +
- + g_return_val_if_fail (tmpl != NULL, -1);
- +
- + for (count = 0; count < 100; count++)
- + {
- + glnx_gen_temp_name (tmpl);
- +
- + if (mkdirat (dfd, tmpl, mode) == -1)
- + {
- + if (errno == EEXIST)
- + continue;
- +
- + /* Any other error will apply also to other names we might
- + * try, and there are 2^32 or so of them, so give up now.
- + */
- + return glnx_throw_errno_prefix (error, "mkdirat");
- + }
- +
- + return TRUE;
- + }
- +
- + g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
- + "mkstempat ran out of combinations to try.");
- + return FALSE;
- +}
- +
- +/**
- + * glnx_mkdtempat_open:
- + * @dfd: Directory FD
- + * @tmpl: (type filename): template directory name, last 6 characters will be replaced
- + * @mode: permissions to create the temporary directory with
- + * @out_dfd: (out caller-allocates): Return location for an FD for the new
- + * temporary directory, or `-1` on error
- + * @error: Return location for a #GError, or %NULL
- + *
- + * Similar to glnx_mkdtempat(), except it will open the resulting temporary
- + * directory and return a directory FD to it.
- + *
- + * Returns: %TRUE on success, %FALSE otherwise
- + * Since: UNRELEASED
- + */
- +gboolean
- +glnx_mkdtempat_open (int dfd,
- + gchar *tmpl,
- + int mode,
- + int *out_dfd,
- + GError **error)
- +{
- + /* FIXME: Ideally we could use openat(O_DIRECTORY | O_CREAT | O_EXCL) here
- + * to create and open the directory atomically, but that’s not supported by
- + * current kernel versions: http://www.openwall.com/lists/oss-security/2014/11/26/14
- + * (Tested on kernel 4.10.10-200.fc25.x86_64). For the moment, accept a
- + * TOCTTOU race here. */
- + *out_dfd = -1;
- +
- + if (!glnx_mkdtempat (dfd, tmpl, mode, error))
- + return FALSE;
- +
- + return glnx_opendirat (dfd, tmpl, FALSE, out_dfd, error);
- +}
- +
- +/**
- + * glnx_mkdtempat_open_in_system:
- + * @tmpl: (type filename): template directory name, last 6 characters will be replaced
- + * @mode: permissions to create the temporary directory with
- + * @out_dfd: (out caller-allocates): Return location for an FD for the new
- + * temporary directory, or `-1` on error
- + * @error: Return location for a #GError, or %NULL
- + *
- + * Similar to glnx_mkdtempat_open(), except it will use the system temporary
- + * directory (from g_get_tmp_dir()) as the parent directory to @tmpl.
- + *
- + * Returns: %TRUE on success, %FALSE otherwise
- + * Since: UNRELEASED
- + */
- +gboolean
- +glnx_mkdtempat_open_in_system (gchar *tmpl,
- + int mode,
- + int *out_dfd,
- + GError **error)
- +{
- + glnx_fd_close int tmp_dfd = -1;
- +
- + *out_dfd = -1;
- +
- + if (!glnx_opendirat (-1, g_get_tmp_dir (), TRUE, &tmp_dfd, error))
- + return FALSE;
- +
- + return glnx_mkdtempat_open (tmp_dfd, tmpl, mode, out_dfd, error);
- +}
- +
- +
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-dirfd.h flatpak-builder-0.10.6/libglnx/glnx-dirfd.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-dirfd.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-dirfd.h 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,132 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <glnx-backport-autocleanups.h>
- +#include <glnx-macros.h>
- +#include <glnx-errors.h>
- +#include <limits.h>
- +#include <dirent.h>
- +#include <sys/stat.h>
- +#include <fcntl.h>
- +
- +G_BEGIN_DECLS
- +
- +/**
- + * glnx_dirfd_canonicalize:
- + * @fd: A directory file descriptor
- + *
- + * It's often convenient in programs to use `-1` for "unassigned fd",
- + * and also because gobject-introspection doesn't support `AT_FDCWD`,
- + * libglnx honors `-1` to mean `AT_FDCWD`. This small inline function
- + * canonicalizes `-1 -> AT_FDCWD`.
- + */
- +static inline int
- +glnx_dirfd_canonicalize (int fd)
- +{
- + if (fd == -1)
- + return AT_FDCWD;
- + return fd;
- +}
- +
- +struct GLnxDirFdIterator {
- + gboolean initialized;
- + int fd;
- + gpointer padding_data[4];
- +};
- +
- +typedef struct GLnxDirFdIterator GLnxDirFdIterator;
- +gboolean glnx_dirfd_iterator_init_at (int dfd, const char *path,
- + gboolean follow,
- + GLnxDirFdIterator *dfd_iter, GError **error);
- +gboolean glnx_dirfd_iterator_init_take_fd (int *dfd, GLnxDirFdIterator *dfd_iter, GError **error);
- +gboolean glnx_dirfd_iterator_next_dent (GLnxDirFdIterator *dfd_iter,
- + struct dirent **out_dent,
- + GCancellable *cancellable,
- + GError **error);
- +gboolean glnx_dirfd_iterator_next_dent_ensure_dtype (GLnxDirFdIterator *dfd_iter,
- + struct dirent **out_dent,
- + GCancellable *cancellable,
- + GError **error);
- +void glnx_dirfd_iterator_clear (GLnxDirFdIterator *dfd_iter);
- +
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxDirFdIterator, glnx_dirfd_iterator_clear)
- +
- +int glnx_opendirat_with_errno (int dfd,
- + const char *path,
- + gboolean follow);
- +
- +gboolean glnx_opendirat (int dfd,
- + const char *path,
- + gboolean follow,
- + int *out_fd,
- + GError **error);
- +
- +char *glnx_fdrel_abspath (int dfd,
- + const char *path);
- +
- +void glnx_gen_temp_name (gchar *tmpl);
- +
- +/**
- + * glnx_ensure_dir:
- + * @dfd: directory fd
- + * @path: Directory path
- + * @mode: Mode
- + * @error: Return location for a #GError, or %NULL
- + *
- + * Wrapper around mkdirat() which ignores adds #GError support, ensures that
- + * it retries on %EINTR, and also ignores `EEXIST`.
- + *
- + * See also `glnx_shutil_mkdir_p_at()` for recursive handling.
- + *
- + * Returns: %TRUE on success, %FALSE otherwise
- + */
- +static inline gboolean
- +glnx_ensure_dir (int dfd,
- + const char *path,
- + mode_t mode,
- + GError **error)
- +{
- + if (TEMP_FAILURE_RETRY (mkdirat (dfd, path, mode)) != 0)
- + {
- + if (G_UNLIKELY (errno != EEXIST))
- + return glnx_throw_errno_prefix (error, "mkdirat(%s)", path);
- + }
- + return TRUE;
- +}
- +
- +gboolean glnx_mkdtempat (int dfd,
- + gchar *tmpl,
- + int mode,
- + GError **error);
- +
- +gboolean glnx_mkdtempat_open (int dfd,
- + gchar *tmpl,
- + int mode,
- + int *out_dfd,
- + GError **error);
- +
- +gboolean glnx_mkdtempat_open_in_system (gchar *tmpl,
- + int mode,
- + int *out_dfd,
- + GError **error);
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-errors.c flatpak-builder-0.10.6/libglnx/glnx-errors.c
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-errors.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-errors.c 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,56 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +
- +#include <glnx-backport-autocleanups.h>
- +#include <glnx-errors.h>
- +
- +void
- +glnx_real_set_prefix_error_va (GError *error,
- + const char *format,
- + va_list args)
- +{
- + if (error == NULL)
- + return;
- +
- + g_autofree char *old_msg = g_steal_pointer (&error->message);
- + g_autoptr(GString) buf = g_string_new ("");
- + g_string_append_vprintf (buf, format, args);
- + g_string_append (buf, ": ");
- + g_string_append (buf, old_msg);
- + error->message = g_string_free (g_steal_pointer (&buf), FALSE);
- +}
- +
- +void
- +glnx_real_set_prefix_error_from_errno_va (GError **error,
- + gint errsv,
- + const char *format,
- + va_list args)
- +{
- + if (!error)
- + return;
- +
- + g_set_error_literal (error,
- + G_IO_ERROR,
- + g_io_error_from_errno (errsv),
- + g_strerror (errsv));
- + glnx_real_set_prefix_error_va (*error, format, args);
- +}
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-errors.h flatpak-builder-0.10.6/libglnx/glnx-errors.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-errors.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-errors.h 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,197 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <glnx-backport-autocleanups.h>
- +#include <errno.h>
- +
- +G_BEGIN_DECLS
- +
- +/* Set @error with G_IO_ERROR/G_IO_ERROR_FAILED.
- + *
- + * This function returns %FALSE so it can be used conveniently in a single
- + * statement:
- + *
- + * ```
- + * if (strcmp (foo, "somevalue") != 0)
- + * return glnx_throw (error, "key must be somevalue, not '%s'", foo);
- + * ```
- + */
- +static inline gboolean G_GNUC_PRINTF (2,3)
- +glnx_throw (GError **error, const char *fmt, ...)
- +{
- + if (error == NULL)
- + return FALSE;
- +
- + va_list args;
- + va_start (args, fmt);
- + GError *new = g_error_new_valist (G_IO_ERROR, G_IO_ERROR_FAILED, fmt, args);
- + va_end (args);
- + g_propagate_error (error, g_steal_pointer (&new));
- + return FALSE;
- +}
- +
- +/* Like `glnx_throw ()`, but returns %NULL. */
- +#define glnx_null_throw(error, args...) \
- + ({glnx_throw (error, args); NULL;})
- +
- +/* Implementation detail of glnx_throw_prefix() */
- +void glnx_real_set_prefix_error_va (GError *error,
- + const char *format,
- + va_list args) G_GNUC_PRINTF (2,0);
- +
- +/* Prepend to @error's message by `$prefix: ` where `$prefix` is computed via
- + * printf @fmt. Returns %FALSE so it can be used conveniently in a single
- + * statement:
- + *
- + * ```
- + * if (!function_that_fails (s, error))
- + * return glnx_throw_prefix (error, "while handling '%s'", s);
- + * ```
- + * */
- +static inline gboolean G_GNUC_PRINTF (2,3)
- +glnx_prefix_error (GError **error, const char *fmt, ...)
- +{
- + if (error == NULL)
- + return FALSE;
- +
- + va_list args;
- + va_start (args, fmt);
- + glnx_real_set_prefix_error_va (*error, fmt, args);
- + va_end (args);
- + return FALSE;
- +}
- +
- +/* Like `glnx_prefix_error ()`, but returns %NULL. */
- +#define glnx_prefix_error_null(error, args...) \
- + ({glnx_prefix_error (error, args); NULL;})
- +
- +/**
- + * GLNX_AUTO_PREFIX_ERROR:
- + *
- + * An autocleanup-based macro to automatically call `g_prefix_error()` (also with a colon+space `: `)
- + * when it goes out of scope. This is useful when one wants error strings built up by the callee
- + * function, not all callers.
- + *
- + * ```
- + * gboolean start_http_request (..., GError **error)
- + * {
- + * GLNX_AUTO_PREFIX_ERROR ("HTTP request", error)
- + *
- + * if (!libhttp_request_start (..., error))
- + * return FALSE;
- + * ...
- + * return TRUE;
- + * ```
- + */
- +typedef struct {
- + const char *prefix;
- + GError **error;
- +} GLnxAutoErrorPrefix;
- +static inline void
- +glnx_cleanup_auto_prefix_error (GLnxAutoErrorPrefix *prefix)
- +{
- + if (prefix->error && *(prefix->error))
- + g_prefix_error (prefix->error, "%s: ", prefix->prefix);
- +}
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxAutoErrorPrefix, glnx_cleanup_auto_prefix_error)
- +#define GLNX_AUTO_PREFIX_ERROR(text, error) \
- + G_GNUC_UNUSED g_auto(GLnxAutoErrorPrefix) _GLNX_MAKE_ANONYMOUS(_glnxautoprefixerror_) = { text, error }
- +
- +/* Set @error using the value of `g_strerror (errno)`.
- + *
- + * This function returns %FALSE so it can be used conveniently in a single
- + * statement:
- + *
- + * ```
- + * if (unlinkat (fd, somepathname) < 0)
- + * return glnx_throw_errno (error);
- + * ```
- + */
- +static inline gboolean
- +glnx_throw_errno (GError **error)
- +{
- + /* Save the value of errno, in case one of the
- + * intermediate function calls happens to set it.
- + */
- + int errsv = errno;
- + g_set_error_literal (error, G_IO_ERROR,
- + g_io_error_from_errno (errsv),
- + g_strerror (errsv));
- + /* We also restore the value of errno, since that's
- + * what was done in a long-ago libgsystem commit
- + * https://git.gnome.org/browse/libgsystem/commit/?id=ed106741f7a0596dc8b960b31fdae671d31d666d
- + * but I certainly can't remember now why I did that.
- + */
- + errno = errsv;
- + return FALSE;
- +}
- +
- +/* Like glnx_throw_errno(), but yields a NULL pointer. */
- +#define glnx_null_throw_errno(error) \
- + ({glnx_throw_errno (error); NULL;})
- +
- +/* Implementation detail of glnx_throw_errno_prefix() */
- +void glnx_real_set_prefix_error_from_errno_va (GError **error,
- + gint errsv,
- + const char *format,
- + va_list args) G_GNUC_PRINTF (3,0);
- +
- +/* Set @error using the value of `$prefix: g_strerror (errno)` where `$prefix`
- + * is computed via printf @fmt.
- + *
- + * This function returns %FALSE so it can be used conveniently in a single
- + * statement:
- + *
- + * ```
- + * return glnx_throw_errno_prefix (error, "unlinking %s", pathname);
- + * ```
- + */
- +static inline gboolean G_GNUC_PRINTF (2,3)
- +glnx_throw_errno_prefix (GError **error, const char *fmt, ...)
- +{
- + int errsv = errno;
- + va_list args;
- + va_start (args, fmt);
- + glnx_real_set_prefix_error_from_errno_va (error, errsv, fmt, args);
- + va_end (args);
- + /* See comment above about preserving errno */
- + errno = errsv;
- + return FALSE;
- +}
- +
- +/* Like glnx_throw_errno_prefix(), but yields a NULL pointer. */
- +#define glnx_null_throw_errno_prefix(error, args...) \
- + ({glnx_throw_errno_prefix (error, args); NULL;})
- +
- +/* BEGIN LEGACY APIS */
- +
- +#define glnx_set_error_from_errno(error) \
- + do { \
- + glnx_throw_errno (error); \
- + } while (0);
- +
- +#define glnx_set_prefix_error_from_errno(error, format, args...) \
- + do { \
- + glnx_throw_errno_prefix (error, format, args); \
- + } while (0);
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-fdio.c flatpak-builder-0.10.6/libglnx/glnx-fdio.c
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-fdio.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-fdio.c 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,1111 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * Portions derived from systemd:
- + * Copyright 2010 Lennart Poettering
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +
- +#include <string.h>
- +#include <stdio.h>
- +#include <stdlib.h>
- +#include <stdint.h>
- +#include <stdbool.h>
- +#include <sys/ioctl.h>
- +#include <sys/sendfile.h>
- +#include <errno.h>
- +
- +#include <glnx-fdio.h>
- +#include <glnx-dirfd.h>
- +#include <glnx-errors.h>
- +#include <glnx-xattrs.h>
- +#include <glnx-backport-autoptr.h>
- +#include <glnx-local-alloc.h>
- +#include <glnx-missing.h>
- +
- +/* The standardized version of BTRFS_IOC_CLONE */
- +#ifndef FICLONE
- +#define FICLONE _IOW(0x94, 9, int)
- +#endif
- +
- +/* Returns the number of chars needed to format variables of the
- + * specified type as a decimal string. Adds in extra space for a
- + * negative '-' prefix (hence works correctly on signed
- + * types). Includes space for the trailing NUL. */
- +#define DECIMAL_STR_MAX(type) \
- + (2+(sizeof(type) <= 1 ? 3 : \
- + sizeof(type) <= 2 ? 5 : \
- + sizeof(type) <= 4 ? 10 : \
- + sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)])))
- +
- +gboolean
- +glnx_stdio_file_flush (FILE *f, GError **error)
- +{
- + if (fflush (f) != 0)
- + return glnx_throw_errno_prefix (error, "fflush");
- + if (ferror (f) != 0)
- + return glnx_throw_errno_prefix (error, "ferror");
- + return TRUE;
- +}
- +
- +/* An implementation of renameat2(..., RENAME_NOREPLACE)
- + * with fallback to a non-atomic version.
- + */
- +int
- +glnx_renameat2_noreplace (int olddirfd, const char *oldpath,
- + int newdirfd, const char *newpath)
- +{
- +#ifndef ENABLE_WRPSEUDO_COMPAT
- + if (renameat2 (olddirfd, oldpath, newdirfd, newpath, RENAME_NOREPLACE) < 0)
- + {
- + if (G_IN_SET(errno, EINVAL, ENOSYS))
- + {
- + /* Fall through */
- + }
- + else
- + {
- + return -1;
- + }
- + }
- + else
- + return TRUE;
- +#endif
- +
- + if (linkat (olddirfd, oldpath, newdirfd, newpath, 0) < 0)
- + return -1;
- +
- + if (unlinkat (olddirfd, oldpath, 0) < 0)
- + return -1;
- +
- + return 0;
- +}
- +
- +static gboolean
- +rename_file_noreplace_at (int olddirfd, const char *oldpath,
- + int newdirfd, const char *newpath,
- + gboolean ignore_eexist,
- + GError **error)
- +{
- + if (glnx_renameat2_noreplace (olddirfd, oldpath,
- + newdirfd, newpath) < 0)
- + {
- + if (errno == EEXIST && ignore_eexist)
- + {
- + (void) unlinkat (olddirfd, oldpath, 0);
- + return TRUE;
- + }
- + else
- + return glnx_throw_errno (error);
- + }
- + return TRUE;
- +}
- +
- +/* An implementation of renameat2(..., RENAME_EXCHANGE)
- + * with fallback to a non-atomic version.
- + */
- +int
- +glnx_renameat2_exchange (int olddirfd, const char *oldpath,
- + int newdirfd, const char *newpath)
- +{
- +#ifndef ENABLE_WRPSEUDO_COMPAT
- + if (renameat2 (olddirfd, oldpath, newdirfd, newpath, RENAME_EXCHANGE) == 0)
- + return 0;
- + else
- + {
- + if (G_IN_SET(errno, ENOSYS, EINVAL))
- + {
- + /* Fall through */
- + }
- + else
- + {
- + return -1;
- + }
- + }
- +#endif
- +
- + /* Fallback */
- + { const char *old_tmp_name = glnx_strjoina (oldpath, ".XXXXXX");
- +
- + /* Move old out of the way */
- + if (renameat (olddirfd, oldpath, olddirfd, old_tmp_name) < 0)
- + return -1;
- + /* Now move new into its place */
- + if (renameat (newdirfd, newpath, olddirfd, oldpath) < 0)
- + return -1;
- + /* And finally old(tmp) into new */
- + if (renameat (olddirfd, old_tmp_name, newdirfd, newpath) < 0)
- + return -1;
- + }
- + return 0;
- +}
- +
- +/* Deallocate a tmpfile, closing the fd and deleting the path, if any. This is
- + * normally called by default by the autocleanup attribute, but you can also
- + * invoke this directly.
- + */
- +void
- +glnx_tmpfile_clear (GLnxTmpfile *tmpf)
- +{
- + /* Support being passed NULL so we work nicely in a GPtrArray */
- + if (!tmpf)
- + return;
- + if (!tmpf->initialized)
- + return;
- + if (tmpf->fd == -1)
- + return;
- + (void) close (tmpf->fd);
- + /* If ->path is set, we're likely aborting due to an error. Clean it up */
- + if (tmpf->path)
- + {
- + (void) unlinkat (tmpf->src_dfd, tmpf->path, 0);
- + g_free (tmpf->path);
- + }
- + tmpf->initialized = FALSE;
- +}
- +
- +/* Allocate a temporary file, using Linux O_TMPFILE if available. The file mode
- + * will be 0600.
- + *
- + * The result will be stored in @out_tmpf, which is caller allocated
- + * so you can store it on the stack in common scenarios.
- + *
- + * The directory fd @dfd must live at least as long as the output @out_tmpf.
- + */
- +gboolean
- +glnx_open_tmpfile_linkable_at (int dfd,
- + const char *subpath,
- + int flags,
- + GLnxTmpfile *out_tmpf,
- + GError **error)
- +{
- + const guint mode = 0600;
- + glnx_fd_close int fd = -1;
- + int count;
- +
- + dfd = glnx_dirfd_canonicalize (dfd);
- +
- + /* Don't allow O_EXCL, as that has a special meaning for O_TMPFILE */
- + g_return_val_if_fail ((flags & O_EXCL) == 0, FALSE);
- +
- + /* Creates a temporary file, that shall be renamed to "target"
- + * later. If possible, this uses O_TMPFILE – in which case
- + * "ret_path" will be returned as NULL. If not possible a the
- + * tempoary path name used is returned in "ret_path". Use
- + * link_tmpfile() below to rename the result after writing the file
- + * in full. */
- +#if defined(O_TMPFILE) && !defined(DISABLE_OTMPFILE) && !defined(ENABLE_WRPSEUDO_COMPAT)
- + fd = openat (dfd, subpath, O_TMPFILE|flags, mode);
- + if (fd == -1 && !(G_IN_SET(errno, ENOSYS, EISDIR, EOPNOTSUPP)))
- + return glnx_throw_errno_prefix (error, "open(O_TMPFILE)");
- + if (fd != -1)
- + {
- + /* Workaround for https://sourceware.org/bugzilla/show_bug.cgi?id=17523
- + * See also https://github.com/ostreedev/ostree/issues/991
- + */
- + if (fchmod (fd, mode) < 0)
- + return glnx_throw_errno_prefix (error, "fchmod");
- + out_tmpf->initialized = TRUE;
- + out_tmpf->src_dfd = dfd; /* Copied; caller must keep open */
- + out_tmpf->fd = glnx_steal_fd (&fd);
- + out_tmpf->path = NULL;
- + return TRUE;
- + }
- + /* Fallthrough */
- +#endif
- +
- + { g_autofree char *tmp = g_strconcat (subpath, "/tmp.XXXXXX", NULL);
- + const guint count_max = 100;
- +
- + for (count = 0; count < count_max; count++)
- + {
- + glnx_gen_temp_name (tmp);
- +
- + fd = openat (dfd, tmp, O_CREAT|O_EXCL|O_NOFOLLOW|O_NOCTTY|flags, mode);
- + if (fd < 0)
- + {
- + if (errno == EEXIST)
- + continue;
- + else
- + return glnx_throw_errno_prefix (error, "Creating temp file");
- + }
- + else
- + {
- + out_tmpf->initialized = TRUE;
- + out_tmpf->src_dfd = dfd; /* Copied; caller must keep open */
- + out_tmpf->fd = glnx_steal_fd (&fd);
- + out_tmpf->path = g_steal_pointer (&tmp);
- + return TRUE;
- + }
- + }
- + }
- + g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
- + "Exhausted %u attempts to create temporary file", count);
- + return FALSE;
- +}
- +
- +/* A variant of `glnx_open_tmpfile_linkable_at()` which doesn't support linking.
- + * Useful for true temporary storage. The fd will be allocated in /var/tmp to
- + * ensure maximum storage space.
- + */
- +gboolean
- +glnx_open_anonymous_tmpfile (int flags,
- + GLnxTmpfile *out_tmpf,
- + GError **error)
- +{
- + if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, "/var/tmp", flags, out_tmpf, error))
- + return FALSE;
- + if (out_tmpf->path)
- + {
- + (void) unlinkat (out_tmpf->src_dfd, out_tmpf->path, 0);
- + g_clear_pointer (&out_tmpf->path, g_free);
- + }
- + out_tmpf->anonymous = TRUE;
- + out_tmpf->src_dfd = -1;
- + return TRUE;
- +}
- +
- +/* Use this after calling glnx_open_tmpfile_linkable_at() to give
- + * the file its final name (link into place).
- + */
- +gboolean
- +glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
- + GLnxLinkTmpfileReplaceMode mode,
- + int target_dfd,
- + const char *target,
- + GError **error)
- +{
- + const gboolean replace = (mode == GLNX_LINK_TMPFILE_REPLACE);
- + const gboolean ignore_eexist = (mode == GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST);
- +
- + g_return_val_if_fail (!tmpf->anonymous, FALSE);
- + g_return_val_if_fail (tmpf->fd >= 0, FALSE);
- + g_return_val_if_fail (tmpf->src_dfd == AT_FDCWD || tmpf->src_dfd >= 0, FALSE);
- +
- + /* Unlike the original systemd code, this function also supports
- + * replacing existing files.
- + */
- +
- + /* We have `tmpfile_path` for old systems without O_TMPFILE. */
- + if (tmpf->path)
- + {
- + if (replace)
- + {
- + /* We have a regular tempfile, we're overwriting - this is a
- + * simple renameat().
- + */
- + if (renameat (tmpf->src_dfd, tmpf->path, target_dfd, target) < 0)
- + return glnx_throw_errno_prefix (error, "renameat");
- + }
- + else
- + {
- + /* We need to use renameat2(..., NOREPLACE) or emulate it */
- + if (!rename_file_noreplace_at (tmpf->src_dfd, tmpf->path, target_dfd, target,
- + ignore_eexist,
- + error))
- + return FALSE;
- + }
- + /* Now, clear the pointer so we don't try to unlink it */
- + g_clear_pointer (&tmpf->path, g_free);
- + }
- + else
- + {
- + /* This case we have O_TMPFILE, so our reference to it is via /proc/self/fd */
- + char proc_fd_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(tmpf->fd) + 1];
- +
- + sprintf (proc_fd_path, "/proc/self/fd/%i", tmpf->fd);
- +
- + if (replace)
- + {
- + /* In this case, we had our temp file atomically hidden, but now
- + * we need to make it visible in the FS so we can do a rename.
- + * Ideally, linkat() would gain AT_REPLACE or so.
- + */
- + /* TODO - avoid double alloca, we can just alloca a copy of
- + * the pathname plus space for tmp.XXXXX */
- + char *dnbuf = strdupa (target);
- + const char *dn = dirname (dnbuf);
- + char *tmpname_buf = glnx_strjoina (dn, "/tmp.XXXXXX");
- + guint count;
- + const guint count_max = 100;
- +
- + for (count = 0; count < count_max; count++)
- + {
- + glnx_gen_temp_name (tmpname_buf);
- +
- + if (linkat (AT_FDCWD, proc_fd_path, target_dfd, tmpname_buf, AT_SYMLINK_FOLLOW) < 0)
- + {
- + if (errno == EEXIST)
- + continue;
- + else
- + return glnx_throw_errno_prefix (error, "linkat");
- + }
- + else
- + break;
- + }
- + if (count == count_max)
- + {
- + g_set_error (error, G_IO_ERROR, G_IO_ERROR_EXISTS,
- + "Exhausted %u attempts to create temporary file", count);
- + return FALSE;
- + }
- + if (!glnx_renameat (target_dfd, tmpname_buf, target_dfd, target, error))
- + {
- + /* This is currently the only case where we need to have
- + * a cleanup unlinkat() still with O_TMPFILE.
- + */
- + (void) unlinkat (target_dfd, tmpname_buf, 0);
- + return FALSE;
- + }
- + }
- + else
- + {
- + if (linkat (AT_FDCWD, proc_fd_path, target_dfd, target, AT_SYMLINK_FOLLOW) < 0)
- + {
- + if (errno == EEXIST && mode == GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST)
- + ;
- + else
- + return glnx_throw_errno_prefix (error, "linkat");
- + }
- + }
- +
- + }
- + return TRUE;
- +}
- +
- +/**
- + * glnx_openat_rdonly:
- + * @dfd: File descriptor for origin directory
- + * @path: Pathname, relative to @dfd
- + * @follow: Whether or not to follow symbolic links in the final component
- + * @out_fd: (out): File descriptor
- + * @error: Error
- + *
- + * Use openat() to open a file, with flags `O_RDONLY | O_CLOEXEC | O_NOCTTY`.
- + * Like the other libglnx wrappers, will use `TEMP_FAILURE_RETRY` and
- + * also includes @path in @error in case of failure.
- + */
- +gboolean
- +glnx_openat_rdonly (int dfd,
- + const char *path,
- + gboolean follow,
- + int *out_fd,
- + GError **error)
- +{
- + int flags = O_RDONLY | O_CLOEXEC | O_NOCTTY;
- + if (!follow)
- + flags |= O_NOFOLLOW;
- + int fd = TEMP_FAILURE_RETRY (openat (dfd, path, flags));
- + if (fd == -1)
- + return glnx_throw_errno_prefix (error, "openat(%s)", path);
- + *out_fd = fd;
- + return TRUE;
- +}
- +
- +static guint8*
- +glnx_fd_readall_malloc (int fd,
- + gsize *out_len,
- + gboolean nul_terminate,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + const guint maxreadlen = 4096;
- +
- + struct stat stbuf;
- + if (TEMP_FAILURE_RETRY (fstat (fd, &stbuf)) < 0)
- + return glnx_null_throw_errno (error);
- +
- + gsize buf_allocated;
- + if (S_ISREG (stbuf.st_mode) && stbuf.st_size > 0)
- + buf_allocated = stbuf.st_size;
- + else
- + buf_allocated = 16;
- +
- + g_autofree guint8* buf = g_malloc (buf_allocated);
- +
- + gsize buf_size = 0;
- + while (TRUE)
- + {
- + gsize readlen = MIN (buf_allocated - buf_size, maxreadlen);
- +
- + if (g_cancellable_set_error_if_cancelled (cancellable, error))
- + return FALSE;
- +
- + gssize bytes_read;
- + do
- + bytes_read = read (fd, buf + buf_size, readlen);
- + while (G_UNLIKELY (bytes_read == -1 && errno == EINTR));
- + if (G_UNLIKELY (bytes_read == -1))
- + return glnx_null_throw_errno (error);
- + if (bytes_read == 0)
- + break;
- +
- + buf_size += bytes_read;
- + if (buf_allocated - buf_size < maxreadlen)
- + buf = g_realloc (buf, buf_allocated *= 2);
- + }
- +
- + if (nul_terminate)
- + {
- + if (buf_allocated - buf_size == 0)
- + buf = g_realloc (buf, buf_allocated + 1);
- + buf[buf_size] = '\0';
- + }
- +
- + *out_len = buf_size;
- + return g_steal_pointer (&buf);
- +}
- +
- +/**
- + * glnx_fd_readall_bytes:
- + * @fd: A file descriptor
- + * @cancellable: Cancellable:
- + * @error: Error
- + *
- + * Read all data from file descriptor @fd into a #GBytes. It's
- + * recommended to only use this for small files.
- + *
- + * Returns: (transfer full): A newly allocated #GBytes
- + */
- +GBytes *
- +glnx_fd_readall_bytes (int fd,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + gsize len;
- + guint8 *buf = glnx_fd_readall_malloc (fd, &len, FALSE, cancellable, error);
- + if (!buf)
- + return NULL;
- + return g_bytes_new_take (buf, len);
- +}
- +
- +/**
- + * glnx_fd_readall_utf8:
- + * @fd: A file descriptor
- + * @out_len: (out): Returned length
- + * @cancellable: Cancellable:
- + * @error: Error
- + *
- + * Read all data from file descriptor @fd, validating
- + * the result as UTF-8.
- + *
- + * Returns: (transfer full): A string validated as UTF-8, or %NULL on error.
- + */
- +char *
- +glnx_fd_readall_utf8 (int fd,
- + gsize *out_len,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + gsize len;
- + g_autofree guint8 *buf = glnx_fd_readall_malloc (fd, &len, TRUE, cancellable, error);
- + if (!buf)
- + return FALSE;
- +
- + if (!g_utf8_validate ((char*)buf, len, NULL))
- + {
- + g_set_error (error,
- + G_IO_ERROR,
- + G_IO_ERROR_INVALID_DATA,
- + "Invalid UTF-8");
- + return FALSE;
- + }
- +
- + if (out_len)
- + *out_len = len;
- + return (char*)g_steal_pointer (&buf);
- +}
- +
- +/**
- + * glnx_file_get_contents_utf8_at:
- + * @dfd: Directory file descriptor
- + * @subpath: Path relative to @dfd
- + * @out_len: (out) (allow-none): Optional length
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Read the entire contents of the file referred
- + * to by @dfd and @subpath, validate the result as UTF-8.
- + * The length is optionally stored in @out_len.
- + *
- + * Returns: (transfer full): UTF-8 validated text, or %NULL on error
- + */
- +char *
- +glnx_file_get_contents_utf8_at (int dfd,
- + const char *subpath,
- + gsize *out_len,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + dfd = glnx_dirfd_canonicalize (dfd);
- +
- + glnx_fd_close int fd = -1;
- + if (!glnx_openat_rdonly (dfd, subpath, TRUE, &fd, error))
- + return NULL;
- +
- + gsize len;
- + g_autofree char *buf = glnx_fd_readall_utf8 (fd, &len, cancellable, error);
- + if (G_UNLIKELY(!buf))
- + return FALSE;
- +
- + if (out_len)
- + *out_len = len;
- + return g_steal_pointer (&buf);
- +}
- +
- +/**
- + * glnx_readlinkat_malloc:
- + * @dfd: Directory file descriptor
- + * @subpath: Subpath
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Read the value of a symlink into a dynamically
- + * allocated buffer.
- + */
- +char *
- +glnx_readlinkat_malloc (int dfd,
- + const char *subpath,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + size_t l = 100;
- +
- + dfd = glnx_dirfd_canonicalize (dfd);
- +
- + for (;;)
- + {
- + g_autofree char *c = NULL;
- + ssize_t n;
- +
- + c = g_malloc (l);
- + n = TEMP_FAILURE_RETRY (readlinkat (dfd, subpath, c, l-1));
- + if (n < 0)
- + return glnx_null_throw_errno (error);
- +
- + if ((size_t) n < l-1)
- + {
- + c[n] = 0;
- + return g_steal_pointer (&c);
- + }
- +
- + l *= 2;
- + }
- +
- + g_assert_not_reached ();
- +}
- +
- +static gboolean
- +copy_symlink_at (int src_dfd,
- + const char *src_subpath,
- + const struct stat *src_stbuf,
- + int dest_dfd,
- + const char *dest_subpath,
- + GLnxFileCopyFlags copyflags,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + g_autofree char *buf = glnx_readlinkat_malloc (src_dfd, src_subpath, cancellable, error);
- + if (!buf)
- + return FALSE;
- +
- + if (TEMP_FAILURE_RETRY (symlinkat (buf, dest_dfd, dest_subpath)) != 0)
- + return glnx_throw_errno_prefix (error, "symlinkat");
- +
- + if (!(copyflags & GLNX_FILE_COPY_NOXATTRS))
- + {
- + g_autoptr(GVariant) xattrs = NULL;
- +
- + if (!glnx_dfd_name_get_all_xattrs (src_dfd, src_subpath, &xattrs,
- + cancellable, error))
- + return FALSE;
- +
- + if (!glnx_dfd_name_set_all_xattrs (dest_dfd, dest_subpath, xattrs,
- + cancellable, error))
- + return FALSE;
- + }
- +
- + if (TEMP_FAILURE_RETRY (fchownat (dest_dfd, dest_subpath,
- + src_stbuf->st_uid, src_stbuf->st_gid,
- + AT_SYMLINK_NOFOLLOW)) != 0)
- + return glnx_throw_errno (error);
- +
- + return TRUE;
- +}
- +
- +#define COPY_BUFFER_SIZE (16*1024)
- +
- +/* Most of the code below is from systemd, but has been reindented to GNU style,
- + * and changed to use POSIX error conventions (return -1, set errno) to more
- + * conveniently fit in with the rest of libglnx.
- + */
- +
- +/* Like write(), but loop until @nbytes are written, or an error
- + * occurs.
- + *
- + * On error, -1 is returned an @errno is set. NOTE: This is an
- + * API change from previous versions of this function.
- + */
- +int
- +glnx_loop_write(int fd, const void *buf, size_t nbytes)
- +{
- + const uint8_t *p = buf;
- +
- + g_return_val_if_fail(fd >= 0, -1);
- + g_return_val_if_fail(buf, -1);
- +
- + errno = 0;
- +
- + while (nbytes > 0)
- + {
- + ssize_t k;
- +
- + k = write(fd, p, nbytes);
- + if (k < 0)
- + {
- + if (errno == EINTR)
- + continue;
- +
- + return -1;
- + }
- +
- + if (k == 0) /* Can't really happen */
- + {
- + errno = EIO;
- + return -1;
- + }
- +
- + p += k;
- + nbytes -= k;
- + }
- +
- + return 0;
- +}
- +
- +/* Read from @fdf until EOF, writing to @fdt. If max_bytes is -1, a full-file
- + * clone will be attempted. Otherwise Linux copy_file_range(), sendfile()
- + * syscall will be attempted. If none of those work, this function will do a
- + * plain read()/write() loop.
- + *
- + * The file descriptor @fdf must refer to a regular file.
- + *
- + * If provided, @max_bytes specifies the maximum number of bytes to read from @fdf.
- + * On error, this function returns `-1` and @errno will be set.
- + */
- +int
- +glnx_regfile_copy_bytes (int fdf, int fdt, off_t max_bytes)
- +{
- + /* Last updates from systemd as of commit 6bda23dd6aaba50cf8e3e6024248cf736cc443ca */
- + static int have_cfr = -1; /* -1 means unknown */
- + bool try_cfr = have_cfr != 0;
- + static int have_sendfile = -1; /* -1 means unknown */
- + bool try_sendfile = have_sendfile != 0;
- +
- + g_return_val_if_fail (fdf >= 0, -1);
- + g_return_val_if_fail (fdt >= 0, -1);
- + g_return_val_if_fail (max_bytes >= -1, -1);
- +
- + /* If we've requested to copy the whole range, try a full-file clone first.
- + */
- + if (max_bytes == (off_t) -1)
- + {
- + if (ioctl (fdt, FICLONE, fdf) == 0)
- + return 0;
- + /* Fall through */
- + struct stat stbuf;
- +
- + /* Gather the size so we can provide the whole thing at once to
- + * copy_file_range() or sendfile().
- + */
- + if (fstat (fdf, &stbuf) < 0)
- + return -1;
- + max_bytes = stbuf.st_size;
- + }
- +
- + while (TRUE)
- + {
- + ssize_t n;
- +
- + /* First, try copy_file_range(). Note this is an inlined version of
- + * try_copy_file_range() from systemd upstream, which works better since
- + * we use POSIX errno style.
- + */
- + if (try_cfr)
- + {
- + n = copy_file_range (fdf, NULL, fdt, NULL, max_bytes, 0u);
- + if (n < 0)
- + {
- + if (errno == ENOSYS)
- + {
- + /* No cfr in kernel, mark as permanently unavailable
- + * and fall through to sendfile().
- + */
- + have_cfr = 0;
- + try_cfr = false;
- + }
- + else if (errno == EXDEV)
- + /* We won't try cfr again for this run, but let's be
- + * conservative and not mark it as available/unavailable until
- + * we know for sure.
- + */
- + try_cfr = false;
- + else
- + return -1;
- + }
- + else
- + {
- + /* cfr worked, mark it as available */
- + if (have_cfr == -1)
- + have_cfr = 1;
- +
- + if (n == 0) /* EOF */
- + break;
- + else
- + /* Success! */
- + goto next;
- + }
- + }
- +
- + /* Next try sendfile(); this version is also changed from systemd upstream
- + * to match the same logic we have for copy_file_range().
- + */
- + if (try_sendfile)
- + {
- + n = sendfile (fdt, fdf, NULL, max_bytes);
- + if (n < 0)
- + {
- + if (G_IN_SET (errno, EINVAL, ENOSYS))
- + {
- + /* No sendfile(), or it doesn't work on regular files.
- + * Mark it as permanently unavailable, and fall through
- + * to plain read()/write().
- + */
- + have_sendfile = 0;
- + try_sendfile = false;
- + }
- + else
- + return -1;
- + }
- + else
- + {
- + /* sendfile() worked, mark it as available */
- + if (have_sendfile == -1)
- + have_sendfile = 1;
- +
- + if (n == 0) /* EOF */
- + break;
- + else if (n > 0)
- + /* Succcess! */
- + goto next;
- + }
- + }
- +
- + /* As a fallback just copy bits by hand */
- + { size_t m = COPY_BUFFER_SIZE;
- + if (max_bytes != (off_t) -1)
- + {
- + if ((off_t) m > max_bytes)
- + m = (size_t) max_bytes;
- + }
- + char buf[m];
- +
- + n = TEMP_FAILURE_RETRY (read (fdf, buf, m));
- + if (n < 0)
- + return -1;
- + if (n == 0) /* EOF */
- + break;
- +
- + if (glnx_loop_write (fdt, buf, (size_t) n) < 0)
- + return -1;
- + }
- +
- + next:
- + if (max_bytes != (off_t) -1)
- + {
- + g_assert_cmpint (max_bytes, >=, n);
- + max_bytes -= n;
- + if (max_bytes == 0)
- + break;
- + }
- + }
- +
- + return 0;
- +}
- +
- +/**
- + * glnx_file_copy_at:
- + * @src_dfd: Source directory fd
- + * @src_subpath: Subpath relative to @src_dfd
- + * @dest_dfd: Target directory fd
- + * @dest_subpath: Destination name
- + * @copyflags: Flags
- + * @cancellable: cancellable
- + * @error: Error
- + *
- + * Perform a full copy of the regular file or
- + * symbolic link from @src_subpath to @dest_subpath.
- + *
- + * If @src_subpath is anything other than a regular
- + * file or symbolic link, an error will be returned.
- + */
- +gboolean
- +glnx_file_copy_at (int src_dfd,
- + const char *src_subpath,
- + struct stat *src_stbuf,
- + int dest_dfd,
- + const char *dest_subpath,
- + GLnxFileCopyFlags copyflags,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + gboolean ret = FALSE;
- + int r;
- + int dest_open_flags;
- + struct timespec ts[2];
- + glnx_fd_close int src_fd = -1;
- + glnx_fd_close int dest_fd = -1;
- + struct stat local_stbuf;
- +
- + if (g_cancellable_set_error_if_cancelled (cancellable, error))
- + goto out;
- +
- + src_dfd = glnx_dirfd_canonicalize (src_dfd);
- + dest_dfd = glnx_dirfd_canonicalize (dest_dfd);
- +
- + /* Automatically do stat() if no stat buffer was supplied */
- + if (!src_stbuf)
- + {
- + if (fstatat (src_dfd, src_subpath, &local_stbuf, AT_SYMLINK_NOFOLLOW) != 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- + src_stbuf = &local_stbuf;
- + }
- +
- + if (S_ISLNK (src_stbuf->st_mode))
- + {
- + return copy_symlink_at (src_dfd, src_subpath, src_stbuf,
- + dest_dfd, dest_subpath,
- + copyflags,
- + cancellable, error);
- + }
- + else if (!S_ISREG (src_stbuf->st_mode))
- + {
- + g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- + "Cannot copy non-regular/non-symlink file: %s", src_subpath);
- + goto out;
- + }
- +
- + if (!glnx_openat_rdonly (src_dfd, src_subpath, FALSE, &src_fd, error))
- + goto out;
- +
- + dest_open_flags = O_WRONLY | O_CREAT | O_CLOEXEC | O_NOCTTY;
- + if (!(copyflags & GLNX_FILE_COPY_OVERWRITE))
- + dest_open_flags |= O_EXCL;
- + else
- + dest_open_flags |= O_TRUNC;
- +
- + dest_fd = TEMP_FAILURE_RETRY (openat (dest_dfd, dest_subpath, dest_open_flags, src_stbuf->st_mode));
- + if (dest_fd == -1)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- +
- + r = glnx_regfile_copy_bytes (src_fd, dest_fd, (off_t) -1);
- + if (r < 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- +
- + if (fchown (dest_fd, src_stbuf->st_uid, src_stbuf->st_gid) != 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- +
- + if (fchmod (dest_fd, src_stbuf->st_mode & 07777) != 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- +
- + ts[0] = src_stbuf->st_atim;
- + ts[1] = src_stbuf->st_mtim;
- + (void) futimens (dest_fd, ts);
- +
- + if (!(copyflags & GLNX_FILE_COPY_NOXATTRS))
- + {
- + g_autoptr(GVariant) xattrs = NULL;
- +
- + if (!glnx_fd_get_all_xattrs (src_fd, &xattrs,
- + cancellable, error))
- + goto out;
- +
- + if (!glnx_fd_set_all_xattrs (dest_fd, xattrs,
- + cancellable, error))
- + goto out;
- + }
- +
- + if (copyflags & GLNX_FILE_COPY_DATASYNC)
- + {
- + if (fdatasync (dest_fd) < 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- + }
- +
- + r = close (dest_fd);
- + dest_fd = -1;
- + if (r < 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- +
- + ret = TRUE;
- + out:
- + if (!ret)
- + (void) unlinkat (dest_dfd, dest_subpath, 0);
- + return ret;
- +}
- +
- +/**
- + * glnx_file_replace_contents_at:
- + * @dfd: Directory fd
- + * @subpath: Subpath
- + * @buf: (array len=len) (element-type guint8): File contents
- + * @len: Length (if `-1`, assume @buf is `NUL` terminated)
- + * @flags: Flags
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Create a new file, atomically replacing the contents of @subpath
- + * (relative to @dfd) with @buf. By default, if the file already
- + * existed, fdatasync() will be used before rename() to ensure stable
- + * contents. This and other behavior can be controlled via @flags.
- + *
- + * Note that no metadata from the existing file is preserved, such as
- + * uid/gid or extended attributes. The default mode will be `0666`,
- + * modified by umask.
- + */
- +gboolean
- +glnx_file_replace_contents_at (int dfd,
- + const char *subpath,
- + const guint8 *buf,
- + gsize len,
- + GLnxFileReplaceFlags flags,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + return glnx_file_replace_contents_with_perms_at (dfd, subpath, buf, len,
- + (mode_t) -1, (uid_t) -1, (gid_t) -1,
- + flags, cancellable, error);
- +}
- +
- +/**
- + * glnx_file_replace_contents_with_perms_at:
- + * @dfd: Directory fd
- + * @subpath: Subpath
- + * @buf: (array len=len) (element-type guint8): File contents
- + * @len: Length (if `-1`, assume @buf is `NUL` terminated)
- + * @mode: File mode; if `-1`, use `0666 - umask`
- + * @flags: Flags
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Like glnx_file_replace_contents_at(), but also supports
- + * setting mode, and uid/gid.
- + */
- +gboolean
- +glnx_file_replace_contents_with_perms_at (int dfd,
- + const char *subpath,
- + const guint8 *buf,
- + gsize len,
- + mode_t mode,
- + uid_t uid,
- + gid_t gid,
- + GLnxFileReplaceFlags flags,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + char *dnbuf = strdupa (subpath);
- + const char *dn = dirname (dnbuf);
- +
- + dfd = glnx_dirfd_canonicalize (dfd);
- +
- + /* With O_TMPFILE we can't use umask, and we can't sanely query the
- + * umask...let's assume something relatively standard.
- + */
- + if (mode == (mode_t) -1)
- + mode = 0644;
- +
- + g_auto(GLnxTmpfile) tmpf = { 0, };
- + if (!glnx_open_tmpfile_linkable_at (dfd, dn, O_WRONLY | O_CLOEXEC,
- + &tmpf, error))
- + return FALSE;
- +
- + if (len == -1)
- + len = strlen ((char*)buf);
- +
- + if (!glnx_try_fallocate (tmpf.fd, 0, len, error))
- + return FALSE;
- +
- + if (glnx_loop_write (tmpf.fd, buf, len) < 0)
- + return glnx_throw_errno (error);
- +
- + if (!(flags & GLNX_FILE_REPLACE_NODATASYNC))
- + {
- + struct stat stbuf;
- + gboolean do_sync;
- +
- + if (fstatat (dfd, subpath, &stbuf, AT_SYMLINK_NOFOLLOW) != 0)
- + {
- + if (errno != ENOENT)
- + return glnx_throw_errno (error);
- + do_sync = (flags & GLNX_FILE_REPLACE_DATASYNC_NEW) > 0;
- + }
- + else
- + do_sync = TRUE;
- +
- + if (do_sync)
- + {
- + if (fdatasync (tmpf.fd) != 0)
- + return glnx_throw_errno_prefix (error, "fdatasync");
- + }
- + }
- +
- + if (uid != (uid_t) -1)
- + {
- + if (fchown (tmpf.fd, uid, gid) != 0)
- + return glnx_throw_errno (error);
- + }
- +
- + if (fchmod (tmpf.fd, mode) != 0)
- + return glnx_throw_errno (error);
- +
- + if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_REPLACE,
- + dfd, subpath, error))
- + return FALSE;
- +
- + return TRUE;
- +}
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-fdio.h flatpak-builder-0.10.6/libglnx/glnx-fdio.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-fdio.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-fdio.h 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,333 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <glnx-backport-autocleanups.h>
- +#include <gio/gfiledescriptorbased.h>
- +#include <limits.h>
- +#include <dirent.h>
- +#include <sys/stat.h>
- +#include <fcntl.h>
- +#include <string.h>
- +#include <stdio.h>
- +#include <sys/xattr.h>
- +/* From systemd/src/shared/util.h */
- +/* When we include libgen.h because we need dirname() we immediately
- + * undefine basename() since libgen.h defines it as a macro to the XDG
- + * version which is really broken. */
- +#include <libgen.h>
- +#undef basename
- +
- +#include <glnx-macros.h>
- +#include <glnx-errors.h>
- +
- +G_BEGIN_DECLS
- +
- +/* Irritatingly, g_basename() which is what we want
- + * is deprecated.
- + */
- +static inline
- +const char *glnx_basename (const char *path)
- +{
- + return (basename) (path);
- +}
- +
- +/* Utilities for standard FILE* */
- +static inline void
- +glnx_stdio_file_cleanup (void *filep)
- +{
- + FILE *f = filep;
- + if (f)
- + fclose (f);
- +}
- +G_DEFINE_AUTOPTR_CLEANUP_FUNC(FILE, glnx_stdio_file_cleanup)
- +
- +/**
- + * glnx_stdio_file_flush:
- + * Call fflush() and check ferror().
- + */
- +gboolean
- +glnx_stdio_file_flush (FILE *f, GError **error);
- +
- +typedef struct {
- + gboolean initialized;
- + gboolean anonymous;
- + int src_dfd;
- + int fd;
- + char *path;
- +} GLnxTmpfile;
- +void glnx_tmpfile_clear (GLnxTmpfile *tmpf);
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxTmpfile, glnx_tmpfile_clear)
- +
- +gboolean
- +glnx_open_anonymous_tmpfile (int flags,
- + GLnxTmpfile *out_tmpf,
- + GError **error);
- +
- +gboolean
- +glnx_open_tmpfile_linkable_at (int dfd,
- + const char *subpath,
- + int flags,
- + GLnxTmpfile *out_tmpf,
- + GError **error);
- +
- +typedef enum {
- + GLNX_LINK_TMPFILE_REPLACE,
- + GLNX_LINK_TMPFILE_NOREPLACE,
- + GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST
- +} GLnxLinkTmpfileReplaceMode;
- +
- +gboolean
- +glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
- + GLnxLinkTmpfileReplaceMode flags,
- + int target_dfd,
- + const char *target,
- + GError **error);
- +
- +gboolean
- +glnx_openat_rdonly (int dfd,
- + const char *path,
- + gboolean follow,
- + int *out_fd,
- + GError **error);
- +
- +GBytes *
- +glnx_fd_readall_bytes (int fd,
- + GCancellable *cancellable,
- + GError **error);
- +
- +char *
- +glnx_fd_readall_utf8 (int fd,
- + gsize *out_len,
- + GCancellable *cancellable,
- + GError **error);
- +
- +char *
- +glnx_file_get_contents_utf8_at (int dfd,
- + const char *subpath,
- + gsize *out_len,
- + GCancellable *cancellable,
- + GError **error);
- +
- +/**
- + * GLnxFileReplaceFlags:
- + * @GLNX_FILE_REPLACE_DATASYNC_NEW: Call fdatasync() even if the file did not exist
- + * @GLNX_FILE_REPLACE_NODATASYNC: Never call fdatasync()
- + *
- + * Flags controlling file replacement.
- + */
- +typedef enum {
- + GLNX_FILE_REPLACE_DATASYNC_NEW = (1 << 0),
- + GLNX_FILE_REPLACE_NODATASYNC = (1 << 1),
- +} GLnxFileReplaceFlags;
- +
- +gboolean
- +glnx_file_replace_contents_at (int dfd,
- + const char *subpath,
- + const guint8 *buf,
- + gsize len,
- + GLnxFileReplaceFlags flags,
- + GCancellable *cancellable,
- + GError **error);
- +
- +gboolean
- +glnx_file_replace_contents_with_perms_at (int dfd,
- + const char *subpath,
- + const guint8 *buf,
- + gsize len,
- + mode_t mode,
- + uid_t uid,
- + gid_t gid,
- + GLnxFileReplaceFlags flags,
- + GCancellable *cancellable,
- + GError **error);
- +
- +char *
- +glnx_readlinkat_malloc (int dfd,
- + const char *subpath,
- + GCancellable *cancellable,
- + GError **error);
- +
- +int
- +glnx_loop_write (int fd, const void *buf, size_t nbytes);
- +
- +int
- +glnx_regfile_copy_bytes (int fdf, int fdt, off_t max_bytes);
- +
- +typedef enum {
- + GLNX_FILE_COPY_OVERWRITE = (1 << 0),
- + GLNX_FILE_COPY_NOXATTRS = (1 << 1),
- + GLNX_FILE_COPY_DATASYNC = (1 << 2)
- +} GLnxFileCopyFlags;
- +
- +gboolean
- +glnx_file_copy_at (int src_dfd,
- + const char *src_subpath,
- + struct stat *src_stbuf,
- + int dest_dfd,
- + const char *dest_subpath,
- + GLnxFileCopyFlags copyflags,
- + GCancellable *cancellable,
- + GError **error);
- +
- +int glnx_renameat2_noreplace (int olddirfd, const char *oldpath,
- + int newdirfd, const char *newpath);
- +int glnx_renameat2_exchange (int olddirfd, const char *oldpath,
- + int newdirfd, const char *newpath);
- +
- +/**
- + * glnx_try_fallocate:
- + * @fd: File descriptor
- + * @size: Size
- + * @error: Error
- + *
- + * Wrapper for Linux fallocate(). Explicitly ignores a @size of zero.
- + * Also, will silently do nothing if the underlying filesystem doesn't
- + * support it. Use this instead of posix_fallocate(), since the glibc fallback
- + * is bad: https://sourceware.org/bugzilla/show_bug.cgi?id=18515
- + */
- +static inline gboolean
- +glnx_try_fallocate (int fd,
- + off_t offset,
- + off_t size,
- + GError **error)
- +{
- + /* This is just nicer than throwing an error */
- + if (size == 0)
- + return TRUE;
- +
- + if (fallocate (fd, 0, offset, size) < 0)
- + {
- + if (G_IN_SET(errno, ENOSYS, EOPNOTSUPP))
- + ; /* Ignore */
- + else
- + return glnx_throw_errno_prefix (error, "fallocate");
- + }
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_fstat:
- + * @fd: FD to stat
- + * @buf: (out caller-allocates): Return location for stat details
- + * @error: Return location for a #GError, or %NULL
- + *
- + * Wrapper around fstat() which adds #GError support and ensures that it retries
- + * on %EINTR.
- + *
- + * Returns: %TRUE on success, %FALSE otherwise
- + * Since: UNRELEASED
- + */
- +static inline gboolean
- +glnx_fstat (int fd,
- + struct stat *buf,
- + GError **error)
- +{
- + if (TEMP_FAILURE_RETRY (fstat (fd, buf)) != 0)
- + return glnx_throw_errno_prefix (error, "fstat");
- + return TRUE;
- +}
- +
- +/**
- + * glnx_fchmod:
- + * @fd: FD
- + * @mode: Mode
- + * @error: Return location for a #GError, or %NULL
- + *
- + * Wrapper around fchmod() which adds #GError support and ensures that it
- + * retries on %EINTR.
- + *
- + * Returns: %TRUE on success, %FALSE otherwise
- + * Since: UNRELEASED
- + */
- +static inline gboolean
- +glnx_fchmod (int fd,
- + mode_t mode,
- + GError **error)
- +{
- + if (TEMP_FAILURE_RETRY (fchmod (fd, mode)) != 0)
- + return glnx_throw_errno_prefix (error, "fchmod");
- + return TRUE;
- +}
- +
- +/**
- + * glnx_fstatat:
- + * @dfd: Directory FD to stat beneath
- + * @path: Path to stat beneath @dfd
- + * @buf: (out caller-allocates): Return location for stat details
- + * @flags: Flags to pass to fstatat()
- + * @error: Return location for a #GError, or %NULL
- + *
- + * Wrapper around fstatat() which adds #GError support and ensures that it
- + * retries on %EINTR.
- + *
- + * Returns: %TRUE on success, %FALSE otherwise
- + * Since: UNRELEASED
- + */
- +static inline gboolean
- +glnx_fstatat (int dfd,
- + const gchar *path,
- + struct stat *buf,
- + int flags,
- + GError **error)
- +{
- + if (TEMP_FAILURE_RETRY (fstatat (dfd, path, buf, flags)) != 0)
- + return glnx_throw_errno_prefix (error, "fstatat(%s)", path);
- + return TRUE;
- +}
- +
- +/**
- + * glnx_renameat:
- + *
- + * Wrapper around renameat() which adds #GError support and ensures that it
- + * retries on %EINTR.
- + */
- +static inline gboolean
- +glnx_renameat (int src_dfd,
- + const gchar *src_path,
- + int dest_dfd,
- + const gchar *dest_path,
- + GError **error)
- +{
- + if (TEMP_FAILURE_RETRY (renameat (src_dfd, src_path, dest_dfd, dest_path)) != 0)
- + return glnx_throw_errno_prefix (error, "renameat(%s, %s)", src_path, dest_path);
- + return TRUE;
- +}
- +
- +/**
- + * glnx_unlinkat:
- + *
- + * Wrapper around unlinkat() which adds #GError support and ensures that it
- + * retries on %EINTR.
- + */
- +static inline gboolean
- +glnx_unlinkat (int dfd,
- + const gchar *path,
- + int flags,
- + GError **error)
- +{
- + if (TEMP_FAILURE_RETRY (unlinkat (dfd, path, flags)) != 0)
- + return glnx_throw_errno_prefix (error, "unlinkat(%s)", path);
- + return TRUE;
- +}
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-local-alloc.c flatpak-builder-0.10.6/libglnx/glnx-local-alloc.c
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-local-alloc.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-local-alloc.c 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,72 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2012,2015 Colin Walters <walters@verbum.org>
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +
- +#include "glnx-local-alloc.h"
- +
- +/**
- + * SECTION:glnxlocalalloc
- + * @title: GLnx local allocation
- + * @short_description: Release local variables automatically when they go out of scope
- + *
- + * These macros leverage the GCC extension __attribute__ ((cleanup))
- + * to allow calling a cleanup function such as g_free() when a
- + * variable goes out of scope. See <ulink
- + * url="http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html">
- + * for more information on the attribute.
- + *
- + * The provided macros make it easy to use the cleanup attribute for
- + * types that come with GLib. The primary two are #glnx_free and
- + * #glnx_unref_object, which correspond to g_free() and
- + * g_object_unref(), respectively.
- + *
- + * The rationale behind this is that particularly when handling error
- + * paths, it can be very tricky to ensure the right variables are
- + * freed. With this, one simply applies glnx_unref_object to a
- + * locally-allocated #GFile for example, and it will be automatically
- + * unreferenced when it goes out of scope.
- + *
- + * Note - you should only use these macros for <emphasis>stack
- + * allocated</emphasis> variables. They don't provide garbage
- + * collection or let you avoid freeing things. They're simply a
- + * compiler assisted deterministic mechanism for calling a cleanup
- + * function when a stack frame ends.
- + *
- + * <example id="gs-lfree"><title>Calling g_free automatically</title>
- + * <programlisting>
- + *
- + * GFile *
- + * create_file (GError **error)
- + * {
- + * glnx_free char *random_id = NULL;
- + *
- + * if (!prepare_file (error))
- + * return NULL;
- + *
- + * random_id = alloc_random_id ();
- + *
- + * return create_file_real (error);
- + * // Note that random_id is freed here automatically
- + * }
- + * </programlisting>
- + * </example>
- + *
- + */
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-local-alloc.h flatpak-builder-0.10.6/libglnx/glnx-local-alloc.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-local-alloc.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-local-alloc.h 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,77 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2012,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <gio/gio.h>
- +#include <errno.h>
- +
- +G_BEGIN_DECLS
- +
- +/**
- + * glnx_unref_object:
- + *
- + * Call g_object_unref() on a variable location when it goes out of
- + * scope. Note that unlike g_object_unref(), the variable may be
- + * %NULL.
- + */
- +#define glnx_unref_object __attribute__ ((cleanup(glnx_local_obj_unref)))
- +static inline void
- +glnx_local_obj_unref (void *v)
- +{
- + GObject *o = *(GObject **)v;
- + if (o)
- + g_object_unref (o);
- +}
- +#define glnx_unref_object __attribute__ ((cleanup(glnx_local_obj_unref)))
- +
- +static inline void
- +glnx_cleanup_close_fdp (int *fdp)
- +{
- + int fd, errsv;
- +
- + g_assert (fdp);
- +
- + fd = *fdp;
- + if (fd >= 0)
- + {
- + errsv = errno;
- + if (close (fd) < 0)
- + g_assert (errno != EBADF);
- + errno = errsv;
- + }
- +}
- +
- +/**
- + * glnx_fd_close:
- + *
- + * Call close() on a variable location when it goes out of scope.
- + */
- +#define glnx_fd_close __attribute__((cleanup(glnx_cleanup_close_fdp)))
- +
- +static inline int
- +glnx_steal_fd (int *fdp)
- +{
- + int fd = *fdp;
- + *fdp = -1;
- + return fd;
- +}
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-lockfile.c flatpak-builder-0.10.6/libglnx/glnx-lockfile.c
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-lockfile.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-lockfile.c 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,185 @@
- +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
- +
- +/***
- + This file is part of systemd.
- + Now copied into libglnx:
- + - Use GError
- +
- + Copyright 2010 Lennart Poettering
- + Copyright 2015 Colin Walters <walters@verbum.org>
- +
- + systemd is free software; you can redistribute it and/or modify it
- + under the terms of the GNU Lesser General Public License as published by
- + the Free Software Foundation; either version 2.1 of the License, or
- + (at your option) any later version.
- +
- + systemd 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
- + Lesser General Public License for more details.
- +
- + You should have received a copy of the GNU Lesser General Public License
- + along with systemd; If not, see <http://www.gnu.org/licenses/>.
- +***/
- +
- +#include "config.h"
- +
- +#include <stdlib.h>
- +#include <stdbool.h>
- +#include <errno.h>
- +#include <string.h>
- +#include <stdio.h>
- +#include <limits.h>
- +#include <unistd.h>
- +#include <sys/types.h>
- +#include <sys/file.h>
- +#include <sys/stat.h>
- +#include <fcntl.h>
- +
- +#include "glnx-lockfile.h"
- +#include "glnx-errors.h"
- +#include "glnx-fdio.h"
- +#include "glnx-backport-autocleanups.h"
- +#include "glnx-local-alloc.h"
- +
- +#define newa(t, n) ((t*) alloca(sizeof(t)*(n)))
- +
- +/**
- + * glnx_make_lock_file:
- + * @dfd: Directory file descriptor (if not `AT_FDCWD`, must have lifetime `>=` @out_lock)
- + * @p: Path
- + * @operation: one of `LOCK_SH`, `LOCK_EX`, `LOCK_UN`, as passed to flock()
- + * @out_lock: (out) (caller allocates): Return location for lock
- + * @error: Error
- + *
- + * Block until a lock file named @p (relative to @dfd) can be created,
- + * using the flags in @operation, returning the lock data in the
- + * caller-allocated location @out_lock.
- + *
- + * This API wraps new-style process locking if available, otherwise
- + * falls back to BSD locks.
- + */
- +gboolean
- +glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *out_lock, GError **error) {
- + glnx_fd_close int fd = -1;
- + g_autofree char *t = NULL;
- + int r;
- +
- + /*
- + * We use UNPOSIX locks if they are available. They have nice
- + * semantics, and are mostly compatible with NFS. However,
- + * they are only available on new kernels. When we detect we
- + * are running on an older kernel, then we fall back to good
- + * old BSD locks. They also have nice semantics, but are
- + * slightly problematic on NFS, where they are upgraded to
- + * POSIX locks, even though locally they are orthogonal to
- + * POSIX locks.
- + */
- +
- + t = g_strdup(p);
- +
- + for (;;) {
- +#ifdef F_OFD_SETLK
- + struct flock fl = {
- + .l_type = (operation & ~LOCK_NB) == LOCK_EX ? F_WRLCK : F_RDLCK,
- + .l_whence = SEEK_SET,
- + };
- +#endif
- + struct stat st;
- +
- + fd = openat(dfd, p, O_CREAT|O_RDWR|O_NOFOLLOW|O_CLOEXEC|O_NOCTTY, 0600);
- + if (fd < 0)
- + return glnx_throw_errno(error);
- +
- + /* Unfortunately, new locks are not in RHEL 7.1 glibc */
- +#ifdef F_OFD_SETLK
- + r = fcntl(fd, (operation & LOCK_NB) ? F_OFD_SETLK : F_OFD_SETLKW, &fl);
- +#else
- + r = -1;
- + errno = EINVAL;
- +#endif
- + if (r < 0) {
- +
- + /* If the kernel is too old, use good old BSD locks */
- + if (errno == EINVAL)
- + r = flock(fd, operation);
- +
- + if (r < 0)
- + return glnx_throw_errno(error);
- + }
- +
- + /* If we acquired the lock, let's check if the file
- + * still exists in the file system. If not, then the
- + * previous exclusive owner removed it and then closed
- + * it. In such a case our acquired lock is worthless,
- + * hence try again. */
- +
- + r = fstat(fd, &st);
- + if (r < 0)
- + return glnx_throw_errno(error);
- + if (st.st_nlink > 0)
- + break;
- +
- + (void) close(fd);
- + fd = -1;
- + }
- +
- + /* Note that if this is not AT_FDCWD, the caller takes responsibility
- + * for the fd's lifetime being >= that of the lock.
- + */
- + out_lock->dfd = dfd;
- + out_lock->path = t;
- + out_lock->fd = fd;
- + out_lock->operation = operation;
- +
- + fd = -1;
- + t = NULL;
- +
- + return TRUE;
- +}
- +
- +void glnx_release_lock_file(GLnxLockFile *f) {
- + int r;
- +
- + if (!f)
- + return;
- +
- + if (f->path) {
- +
- + /* If we are the exclusive owner we can safely delete
- + * the lock file itself. If we are not the exclusive
- + * owner, we can try becoming it. */
- +
- + if (f->fd >= 0 &&
- + (f->operation & ~LOCK_NB) == LOCK_SH) {
- +#ifdef F_OFD_SETLK
- + static const struct flock fl = {
- + .l_type = F_WRLCK,
- + .l_whence = SEEK_SET,
- + };
- +
- + r = fcntl(f->fd, F_OFD_SETLK, &fl);
- +#else
- + r = -1;
- + errno = EINVAL;
- +#endif
- + if (r < 0 && errno == EINVAL)
- + r = flock(f->fd, LOCK_EX|LOCK_NB);
- +
- + if (r >= 0)
- + f->operation = LOCK_EX|LOCK_NB;
- + }
- +
- + if ((f->operation & ~LOCK_NB) == LOCK_EX) {
- + (void) unlinkat(f->dfd, f->path, 0);
- + }
- +
- + g_free(f->path);
- + f->path = NULL;
- + }
- +
- + if (f->fd != -1)
- + (void) close (f->fd);
- + f->fd = -1;
- + f->operation = 0;
- +}
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-lockfile.h flatpak-builder-0.10.6/libglnx/glnx-lockfile.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-lockfile.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-lockfile.h 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,41 @@
- +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
- +
- +#pragma once
- +
- +/***
- + This file is part of systemd.
- +
- + Copyright 2011 Lennart Poettering
- + Copyright 2015 Colin Walters <walters@verbum.org>
- +
- + systemd is free software; you can redistribute it and/or modify it
- + under the terms of the GNU Lesser General Public License as published by
- + the Free Software Foundation; either version 2.1 of the License, or
- + (at your option) any later version.
- +
- + systemd 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
- + Lesser General Public License for more details.
- +
- + You should have received a copy of the GNU Lesser General Public License
- + along with systemd; If not, see <http://www.gnu.org/licenses/>.
- +***/
- +
- +#include "config.h"
- +
- +#include "glnx-backport-autoptr.h"
- +
- +typedef struct GLnxLockFile {
- + int dfd;
- + char *path;
- + int fd;
- + int operation;
- +} GLnxLockFile;
- +
- +gboolean glnx_make_lock_file(int dfd, const char *p, int operation, GLnxLockFile *ret, GError **error);
- +void glnx_release_lock_file(GLnxLockFile *f);
- +
- +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxLockFile, glnx_release_lock_file)
- +
- +#define GLNX_LOCK_FILE_INIT { .fd = -1, .dfd = AT_FDCWD, .path = NULL }
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-macros.h flatpak-builder-0.10.6/libglnx/glnx-macros.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-macros.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-macros.h 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,189 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2017 Colin Walters <walters@verbum.org>
- + * With original source from systemd:
- + * Copyright 2010 Lennart Poettering
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <stdlib.h>
- +#include <string.h>
- +#include <gio/gio.h>
- +
- +G_BEGIN_DECLS
- +
- +/* All of these are for C only. */
- +#ifndef __GI_SCANNER__
- +
- +/* Taken from https://github.com/systemd/systemd/src/basic/string-util.h
- + * at revision v228-666-gcf6c8c4
- + */
- +#define glnx_strjoina(a, ...) \
- + ({ \
- + const char *_appendees_[] = { a, __VA_ARGS__ }; \
- + char *_d_, *_p_; \
- + int _len_ = 0; \
- + unsigned _i_; \
- + for (_i_ = 0; _i_ < G_N_ELEMENTS(_appendees_) && _appendees_[_i_]; _i_++) \
- + _len_ += strlen(_appendees_[_i_]); \
- + _p_ = _d_ = alloca(_len_ + 1); \
- + for (_i_ = 0; _i_ < G_N_ELEMENTS(_appendees_) && _appendees_[_i_]; _i_++) \
- + _p_ = stpcpy(_p_, _appendees_[_i_]); \
- + *_p_ = 0; \
- + _d_; \
- + })
- +
- +#ifndef G_IN_SET
- +
- +/* Infrastructure for `G_IN_SET`; this code is copied from
- + * systemd's macro.h - please treat that version as canonical
- + * and submit patches first to systemd.
- + */
- +#define _G_INSET_CASE_F(X) case X:
- +#define _G_INSET_CASE_F_1(CASE, X) _G_INSET_CASE_F(X)
- +#define _G_INSET_CASE_F_2(CASE, X, ...) CASE(X) _G_INSET_CASE_F_1(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_3(CASE, X, ...) CASE(X) _G_INSET_CASE_F_2(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_4(CASE, X, ...) CASE(X) _G_INSET_CASE_F_3(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_5(CASE, X, ...) CASE(X) _G_INSET_CASE_F_4(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_6(CASE, X, ...) CASE(X) _G_INSET_CASE_F_5(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_7(CASE, X, ...) CASE(X) _G_INSET_CASE_F_6(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_8(CASE, X, ...) CASE(X) _G_INSET_CASE_F_7(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_9(CASE, X, ...) CASE(X) _G_INSET_CASE_F_8(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_10(CASE, X, ...) CASE(X) _G_INSET_CASE_F_9(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_11(CASE, X, ...) CASE(X) _G_INSET_CASE_F_10(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_12(CASE, X, ...) CASE(X) _G_INSET_CASE_F_11(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_13(CASE, X, ...) CASE(X) _G_INSET_CASE_F_12(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_14(CASE, X, ...) CASE(X) _G_INSET_CASE_F_13(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_15(CASE, X, ...) CASE(X) _G_INSET_CASE_F_14(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_16(CASE, X, ...) CASE(X) _G_INSET_CASE_F_15(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_17(CASE, X, ...) CASE(X) _G_INSET_CASE_F_16(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_18(CASE, X, ...) CASE(X) _G_INSET_CASE_F_17(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_19(CASE, X, ...) CASE(X) _G_INSET_CASE_F_18(CASE, __VA_ARGS__)
- +#define _G_INSET_CASE_F_20(CASE, X, ...) CASE(X) _G_INSET_CASE_F_19(CASE, __VA_ARGS__)
- +
- +#define _G_INSET_GET_CASE_F(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,NAME,...) NAME
- +#define _G_INSET_FOR_EACH_MAKE_CASE(...) \
- + _G_INSET_GET_CASE_F(__VA_ARGS__,_G_INSET_CASE_F_20,_G_INSET_CASE_F_19,_G_INSET_CASE_F_18,_G_INSET_CASE_F_17,_G_INSET_CASE_F_16,_G_INSET_CASE_F_15,_G_INSET_CASE_F_14,_G_INSET_CASE_F_13,_G_INSET_CASE_F_12,_G_INSET_CASE_F_11, \
- + _G_INSET_CASE_F_10,_G_INSET_CASE_F_9,_G_INSET_CASE_F_8,_G_INSET_CASE_F_7,_G_INSET_CASE_F_6,_G_INSET_CASE_F_5,_G_INSET_CASE_F_4,_G_INSET_CASE_F_3,_G_INSET_CASE_F_2,_G_INSET_CASE_F_1) \
- + (_G_INSET_CASE_F,__VA_ARGS__)
- +
- +/* Note: claiming the name here even though it isn't upstream yet
- + * https://bugzilla.gnome.org/show_bug.cgi?id=783751
- + */
- +/**
- + * G_IN_SET:
- + * @x: Integer (or smaller) sized value
- + * @...: Elements to compare
- + *
- + * It's quite common to test whether or not `char` values or Unix @errno (among) others
- + * are members of a small set. Normally one has to choose to either use `if (x == val || x == otherval ...)`
- + * or a `switch` statement. This macro is useful to reduce duplication in the first case,
- + * where one can write simply `if (G_IN_SET (x, val, otherval))`, and avoid the verbosity
- + * that the `switch` statement requires.
- + */
- +#define G_IN_SET(x, ...) \
- + ({ \
- + gboolean _g_inset_found = FALSE; \
- + /* If the build breaks in the line below, you need to extend the case macros */ \
- + static G_GNUC_UNUSED char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){__VA_ARGS__})/sizeof(int)]; \
- + switch(x) { \
- + _G_INSET_FOR_EACH_MAKE_CASE(__VA_ARGS__) \
- + _g_inset_found = TRUE; \
- + break; \
- + default: \
- + break; \
- + } \
- + _g_inset_found; \
- + })
- +
- +#endif /* ifndef G_IN_SET */
- +
- +#define _GLNX_CONCAT(a, b) a##b
- +#define _GLNX_CONCAT_INDIRECT(a, b) _GLNX_CONCAT(a, b)
- +#define _GLNX_MAKE_ANONYMOUS(a) _GLNX_CONCAT_INDIRECT(a, __COUNTER__)
- +
- +#define _GLNX_HASH_TABLE_FOREACH_IMPL_KV(guard, ht, it, kt, k, vt, v) \
- + gboolean guard = TRUE; \
- + G_STATIC_ASSERT (sizeof (kt) == sizeof (void*)); \
- + G_STATIC_ASSERT (sizeof (vt) == sizeof (void*)); \
- + for (GHashTableIter it; \
- + guard && ({ g_hash_table_iter_init (&it, ht), TRUE; }); \
- + guard = FALSE) \
- + for (kt k; guard; guard = FALSE) \
- + for (vt v; g_hash_table_iter_next (&it, (gpointer)&k, (gpointer)&v);)
- +
- +
- +/* Cleaner method to iterate over a GHashTable. I.e. rather than
- + *
- + * gpointer k, v;
- + * GHashTableIter it;
- + * g_hash_table_iter_init (&it, table);
- + * while (g_hash_table_iter_next (&it, &k, &v))
- + * {
- + * const char *str = k;
- + * GPtrArray *arr = v;
- + * ...
- + * }
- + *
- + * you can simply do
- + *
- + * GLNX_HASH_TABLE_FOREACH_IT (table, it, const char*, str, GPtrArray*, arr)
- + * {
- + * ...
- + * }
- + *
- + * All variables are scoped within the loop. You may use the `it` variable as
- + * usual, e.g. to remove an element using g_hash_table_iter_remove(&it). There
- + * are shorter variants for the more common cases where you do not need access
- + * to the iterator or to keys/values:
- + *
- + * GLNX_HASH_TABLE_FOREACH (table, const char*, str) { ... }
- + * GLNX_HASH_TABLE_FOREACH_V (table, MyData*, data) { ... }
- + * GLNX_HASH_TABLE_FOREACH_KV (table, const char*, str, MyData*, data) { ... }
- + *
- + */
- +#define GLNX_HASH_TABLE_FOREACH_IT(ht, it, kt, k, vt, v) \
- + _GLNX_HASH_TABLE_FOREACH_IMPL_KV( \
- + _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_guard_), ht, it, kt, k, vt, v)
- +
- +/* Variant of GLNX_HASH_TABLE_FOREACH without having to specify an iterator. An
- + * anonymous iterator will be created. */
- +#define GLNX_HASH_TABLE_FOREACH_KV(ht, kt, k, vt, v) \
- + _GLNX_HASH_TABLE_FOREACH_IMPL_KV( \
- + _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_guard_), ht, \
- + _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_it_), kt, k, vt, v)
- +
- +/* Variant of GLNX_HASH_TABLE_FOREACH_KV which omits unpacking keys. */
- +#define GLNX_HASH_TABLE_FOREACH_V(ht, vt, v) \
- + _GLNX_HASH_TABLE_FOREACH_IMPL_KV( \
- + _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_guard_), ht, \
- + _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_it_), \
- + gpointer, _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_v_), \
- + vt, v)
- +
- +/* Variant of GLNX_HASH_TABLE_FOREACH_KV which omits unpacking vals. */
- +#define GLNX_HASH_TABLE_FOREACH(ht, kt, k) \
- + _GLNX_HASH_TABLE_FOREACH_IMPL_KV( \
- + _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_guard_), ht, \
- + _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_it_), kt, k, \
- + gpointer, _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_v_))
- +
- +#endif /* GI_SCANNER */
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-missing.h flatpak-builder-0.10.6/libglnx/glnx-missing.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-missing.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-missing.h 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,55 @@
- +#pragma once
- +
- +/***
- + This file was originally part of systemd.
- +
- + Copyright 2010 Lennart Poettering
- +
- + systemd is free software; you can redistribute it and/or modify it
- + under the terms of the GNU Lesser General Public License as published by
- + the Free Software Foundation; either version 2.1 of the License, or
- + (at your option) any later version.
- +
- + systemd 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
- + Lesser General Public License for more details.
- +
- + You should have received a copy of the GNU Lesser General Public License
- + along with systemd; If not, see <http://www.gnu.org/licenses/>.
- +***/
- +
- +/* Missing glibc definitions to access certain kernel APIs */
- +
- +#include <errno.h>
- +#include <fcntl.h>
- +#include <stdlib.h>
- +#include <sys/resource.h>
- +#include <sys/syscall.h>
- +#include <uchar.h>
- +#include <unistd.h>
- +
- +#if defined(__i386__) || defined(__x86_64__)
- +
- +/* The precise definition of __O_TMPFILE is arch specific, so let's
- + * just define this on x86 where we know the value. */
- +
- +#ifndef __O_TMPFILE
- +#define __O_TMPFILE 020000000
- +#endif
- +
- +/* a horrid kludge trying to make sure that this will fail on old kernels */
- +#ifndef O_TMPFILE
- +#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
- +#endif
- +
- +#endif
- +
- +#ifndef RENAME_NOREPLACE
- +#define RENAME_NOREPLACE (1 << 0)
- +#endif
- +#ifndef RENAME_EXCHANGE
- +#define RENAME_EXCHANGE (1 << 1)
- +#endif
- +
- +#include "glnx-missing-syscall.h"
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-missing-syscall.h flatpak-builder-0.10.6/libglnx/glnx-missing-syscall.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-missing-syscall.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-missing-syscall.h 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,95 @@
- +/***
- + This file was originally part of systemd.
- +
- + Copyright 2010 Lennart Poettering
- + Copyright 2016 Zbigniew Jędrzejewski-Szmek
- +
- + systemd is free software; you can redistribute it and/or modify it
- + under the terms of the GNU Lesser General Public License as published by
- + the Free Software Foundation; either version 2.1 of the License, or
- + (at your option) any later version.
- +
- + systemd 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
- + Lesser General Public License for more details.
- +
- + You should have received a copy of the GNU Lesser General Public License
- + along with systemd; If not, see <http://www.gnu.org/licenses/>.
- +***/
- +
- +/* Missing glibc definitions to access certain kernel APIs */
- +
- +#if !HAVE_DECL_RENAMEAT2
- +# ifndef __NR_renameat2
- +# if defined __x86_64__
- +# define __NR_renameat2 316
- +# elif defined __arm__
- +# define __NR_renameat2 382
- +# elif defined _MIPS_SIM
- +# if _MIPS_SIM == _MIPS_SIM_ABI32
- +# define __NR_renameat2 4351
- +# endif
- +# if _MIPS_SIM == _MIPS_SIM_NABI32
- +# define __NR_renameat2 6315
- +# endif
- +# if _MIPS_SIM == _MIPS_SIM_ABI64
- +# define __NR_renameat2 5311
- +# endif
- +# elif defined __i386__
- +# define __NR_renameat2 353
- +# else
- +# warning "__NR_renameat2 unknown for your architecture"
- +# endif
- +# endif
- +
- +static inline int renameat2(int oldfd, const char *oldname, int newfd, const char *newname, unsigned flags) {
- +# ifdef __NR_renameat2
- + return syscall(__NR_renameat2, oldfd, oldname, newfd, newname, flags);
- +# else
- + errno = ENOSYS;
- + return -1;
- +# endif
- +}
- +#endif
- +
- +/* Copied from systemd git:
- + commit 6bda23dd6aaba50cf8e3e6024248cf736cc443ca
- + Author: Yu Watanabe <watanabe.yu+github@gmail.com>
- + AuthorDate: Thu Jul 27 20:22:54 2017 +0900
- + Commit: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
- + CommitDate: Thu Jul 27 07:22:54 2017 -0400
- +*/
- +#if !HAVE_DECL_COPY_FILE_RANGE
- +# ifndef __NR_copy_file_range
- +# if defined(__x86_64__)
- +# define __NR_copy_file_range 326
- +# elif defined(__i386__)
- +# define __NR_copy_file_range 377
- +# elif defined __s390__
- +# define __NR_copy_file_range 375
- +# elif defined __arm__
- +# define __NR_copy_file_range 391
- +# elif defined __aarch64__
- +# define __NR_copy_file_range 285
- +# elif defined __powerpc__
- +# define __NR_copy_file_range 379
- +# elif defined __arc__
- +# define __NR_copy_file_range 285
- +# else
- +# warning "__NR_copy_file_range not defined for your architecture"
- +# endif
- +# endif
- +
- +static inline ssize_t copy_file_range(int fd_in, loff_t *off_in,
- + int fd_out, loff_t *off_out,
- + size_t len,
- + unsigned int flags) {
- +# ifdef __NR_copy_file_range
- + return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags);
- +# else
- + errno = ENOSYS;
- + return -1;
- +# endif
- +}
- +#endif
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-shutil.c flatpak-builder-0.10.6/libglnx/glnx-shutil.c
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-shutil.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-shutil.c 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,252 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +
- +#include <string.h>
- +
- +#include <glnx-shutil.h>
- +#include <glnx-errors.h>
- +#include <glnx-local-alloc.h>
- +
- +static gboolean
- +glnx_shutil_rm_rf_children (GLnxDirFdIterator *dfd_iter,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + struct dirent *dent;
- +
- + while (TRUE)
- + {
- + if (!glnx_dirfd_iterator_next_dent_ensure_dtype (dfd_iter, &dent, cancellable, error))
- + return FALSE;
- + if (dent == NULL)
- + break;
- +
- + if (dent->d_type == DT_DIR)
- + {
- + g_auto(GLnxDirFdIterator) child_dfd_iter = { 0, };
- +
- + if (!glnx_dirfd_iterator_init_at (dfd_iter->fd, dent->d_name, FALSE,
- + &child_dfd_iter, error))
- + return FALSE;
- +
- + if (!glnx_shutil_rm_rf_children (&child_dfd_iter, cancellable, error))
- + return FALSE;
- +
- + if (unlinkat (dfd_iter->fd, dent->d_name, AT_REMOVEDIR) == -1)
- + return glnx_throw_errno_prefix (error, "unlinkat");
- + }
- + else
- + {
- + if (unlinkat (dfd_iter->fd, dent->d_name, 0) == -1)
- + {
- + if (errno != ENOENT)
- + return glnx_throw_errno_prefix (error, "unlinkat");
- + }
- + }
- + }
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_shutil_rm_rf_at:
- + * @dfd: A directory file descriptor, or `AT_FDCWD` or `-1` for current
- + * @path: Path
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Recursively delete the filename referenced by the combination of
- + * the directory fd @dfd and @path; it may be a file or directory. No
- + * error is thrown if @path does not exist.
- + */
- +gboolean
- +glnx_shutil_rm_rf_at (int dfd,
- + const char *path,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + glnx_fd_close int target_dfd = -1;
- + g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
- +
- + dfd = glnx_dirfd_canonicalize (dfd);
- +
- + /* With O_NOFOLLOW first */
- + target_dfd = openat (dfd, path,
- + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
- +
- + if (target_dfd == -1)
- + {
- + int errsv = errno;
- + if (errsv == ENOENT)
- + {
- + ;
- + }
- + else if (errsv == ENOTDIR || errsv == ELOOP)
- + {
- + if (unlinkat (dfd, path, 0) != 0)
- + return glnx_throw_errno_prefix (error, "unlinkat");
- + }
- + else
- + return glnx_throw_errno_prefix (error, "open(%s)", path);
- + }
- + else
- + {
- + if (!glnx_dirfd_iterator_init_take_fd (&target_dfd, &dfd_iter, error))
- + return FALSE;
- +
- + if (!glnx_shutil_rm_rf_children (&dfd_iter, cancellable, error))
- + return FALSE;
- +
- + if (unlinkat (dfd, path, AT_REMOVEDIR) == -1)
- + {
- + if (errno != ENOENT)
- + return glnx_throw_errno_prefix (error, "unlinkat");
- + }
- + }
- +
- + return TRUE;
- +}
- +
- +static gboolean
- +mkdir_p_at_internal (int dfd,
- + char *path,
- + int mode,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + gboolean did_recurse = FALSE;
- +
- + if (g_cancellable_set_error_if_cancelled (cancellable, error))
- + return FALSE;
- +
- + again:
- + if (mkdirat (dfd, path, mode) == -1)
- + {
- + if (errno == ENOENT)
- + {
- + char *lastslash;
- +
- + g_assert (!did_recurse);
- +
- + lastslash = strrchr (path, '/');
- + g_assert (lastslash != NULL);
- + /* Note we can mutate the buffer as we dup'd it */
- + *lastslash = '\0';
- +
- + if (!glnx_shutil_mkdir_p_at (dfd, path, mode,
- + cancellable, error))
- + return FALSE;
- +
- + /* Now restore it for another mkdir attempt */
- + *lastslash = '/';
- +
- + did_recurse = TRUE;
- + goto again;
- + }
- + else if (errno == EEXIST)
- + {
- + /* Fall through; it may not have been a directory,
- + * but we'll find that out on the next call up.
- + */
- + }
- + else
- + return glnx_throw_errno_prefix (error, "mkdir(%s)", path);
- + }
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_shutil_mkdir_p_at:
- + * @dfd: Directory fd
- + * @path: Directory path to be created
- + * @mode: Mode for newly created directories
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Similar to g_mkdir_with_parents(), except operates relative to the
- + * directory fd @dfd.
- + *
- + * See also glnx_ensure_dir() for a non-recursive version.
- + */
- +gboolean
- +glnx_shutil_mkdir_p_at (int dfd,
- + const char *path,
- + int mode,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + struct stat stbuf;
- + char *buf;
- +
- + /* Fast path stat to see whether it already exists */
- + if (fstatat (dfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) == 0)
- + {
- + /* Note early return */
- + if (S_ISDIR (stbuf.st_mode))
- + return TRUE;
- + }
- +
- + buf = strdupa (path);
- +
- + if (!mkdir_p_at_internal (dfd, buf, mode, cancellable, error))
- + return FALSE;
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_shutil_mkdir_p_at_open:
- + * @dfd: Directory fd
- + * @path: Directory path to be created
- + * @mode: Mode for newly created directories
- + * @out_dfd: (out caller-allocates): Return location for an FD to @dfd/@path,
- + * or `-1` on error
- + * @cancellable: (nullable): Cancellable, or %NULL
- + * @error: Return location for a #GError, or %NULL
- + *
- + * Similar to glnx_shutil_mkdir_p_at(), except it opens the resulting directory
- + * and returns a directory FD to it. Currently, this is not guaranteed to be
- + * race-free.
- + *
- + * Returns: %TRUE on success, %FALSE otherwise
- + * Since: UNRELEASED
- + */
- +gboolean
- +glnx_shutil_mkdir_p_at_open (int dfd,
- + const char *path,
- + int mode,
- + int *out_dfd,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + /* FIXME: It’s not possible to eliminate the race here until
- + * openat(O_DIRECTORY | O_CREAT) works (and returns a directory rather than a
- + * file). It appears to be not supported in current kernels. (Tested with
- + * 4.10.10-200.fc25.x86_64.) */
- + *out_dfd = -1;
- +
- + if (!glnx_shutil_mkdir_p_at (dfd, path, mode, cancellable, error))
- + return FALSE;
- +
- + return glnx_opendirat (dfd, path, TRUE, out_dfd, error);
- +}
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-shutil.h flatpak-builder-0.10.6/libglnx/glnx-shutil.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-shutil.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-shutil.h 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,48 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <glnx-dirfd.h>
- +
- +G_BEGIN_DECLS
- +
- +gboolean
- +glnx_shutil_rm_rf_at (int dfd,
- + const char *path,
- + GCancellable *cancellable,
- + GError **error);
- +
- +gboolean
- +glnx_shutil_mkdir_p_at (int dfd,
- + const char *path,
- + int mode,
- + GCancellable *cancellable,
- + GError **error);
- +
- +gboolean
- +glnx_shutil_mkdir_p_at_open (int dfd,
- + const char *path,
- + int mode,
- + int *out_dfd,
- + GCancellable *cancellable,
- + GError **error);
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-xattrs.c flatpak-builder-0.10.6/libglnx/glnx-xattrs.c
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-xattrs.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-xattrs.c 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,444 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +
- +#include <string.h>
- +#include <stdio.h>
- +
- +#include <glnx-macros.h>
- +#include <glnx-xattrs.h>
- +#include <glnx-errors.h>
- +#include <glnx-local-alloc.h>
- +
- +static GVariant *
- +variant_new_ay_bytes (GBytes *bytes)
- +{
- + gsize size;
- + gconstpointer data;
- + data = g_bytes_get_data (bytes, &size);
- + g_bytes_ref (bytes);
- + return g_variant_new_from_data (G_VARIANT_TYPE ("ay"), data, size,
- + TRUE, (GDestroyNotify)g_bytes_unref, bytes);
- +}
- +
- +static char *
- +canonicalize_xattrs (char *xattr_string,
- + size_t len)
- +{
- + char *p;
- + GSList *xattrs = NULL;
- + GSList *iter;
- + GString *result;
- +
- + result = g_string_new (0);
- +
- + p = xattr_string;
- + while (p < xattr_string+len)
- + {
- + xattrs = g_slist_prepend (xattrs, p);
- + p += strlen (p) + 1;
- + }
- +
- + xattrs = g_slist_sort (xattrs, (GCompareFunc) strcmp);
- + for (iter = xattrs; iter; iter = iter->next) {
- + g_string_append (result, iter->data);
- + g_string_append_c (result, '\0');
- + }
- +
- + g_slist_free (xattrs);
- + return g_string_free (result, FALSE);
- +}
- +
- +static gboolean
- +read_xattr_name_array (const char *path,
- + int fd,
- + const char *xattrs,
- + size_t len,
- + GVariantBuilder *builder,
- + GError **error)
- +{
- + gboolean ret = FALSE;
- + const char *p;
- + int r;
- + const char *funcstr;
- +
- + g_assert (path != NULL || fd != -1);
- +
- + funcstr = fd != -1 ? "fgetxattr" : "lgetxattr";
- +
- + for (p = xattrs; p < xattrs+len; p = p + strlen (p) + 1)
- + {
- + ssize_t bytes_read;
- + g_autofree char *buf = NULL;
- + g_autoptr(GBytes) bytes = NULL;
- +
- + again:
- + if (fd != -1)
- + bytes_read = fgetxattr (fd, p, NULL, 0);
- + else
- + bytes_read = lgetxattr (path, p, NULL, 0);
- + if (bytes_read < 0)
- + {
- + if (errno == ENODATA)
- + continue;
- +
- + glnx_set_prefix_error_from_errno (error, "%s", funcstr);
- + goto out;
- + }
- + if (bytes_read == 0)
- + continue;
- +
- + buf = g_malloc (bytes_read);
- + if (fd != -1)
- + r = fgetxattr (fd, p, buf, bytes_read);
- + else
- + r = lgetxattr (path, p, buf, bytes_read);
- + if (r < 0)
- + {
- + if (errno == ERANGE)
- + {
- + g_free (g_steal_pointer (&buf));
- + goto again;
- + }
- + else if (errno == ENODATA)
- + continue;
- +
- + glnx_set_prefix_error_from_errno (error, "%s", funcstr);
- + goto out;
- + }
- +
- + bytes = g_bytes_new_take (g_steal_pointer (&buf), bytes_read);
- + g_variant_builder_add (builder, "(@ay@ay)",
- + g_variant_new_bytestring (p),
- + variant_new_ay_bytes (bytes));
- + }
- +
- + ret = TRUE;
- + out:
- + return ret;
- +}
- +
- +static gboolean
- +get_xattrs_impl (const char *path,
- + int fd,
- + GVariant **out_xattrs,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + gboolean ret = FALSE;
- + ssize_t bytes_read, real_size;
- + g_autofree char *xattr_names = NULL;
- + g_autofree char *xattr_names_canonical = NULL;
- + GVariantBuilder builder;
- + gboolean builder_initialized = FALSE;
- + g_autoptr(GVariant) ret_xattrs = NULL;
- +
- + g_assert (path != NULL || fd != -1);
- +
- + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ayay)"));
- + builder_initialized = TRUE;
- +
- + again:
- + if (path)
- + bytes_read = llistxattr (path, NULL, 0);
- + else
- + bytes_read = flistxattr (fd, NULL, 0);
- +
- + if (bytes_read < 0)
- + {
- + if (errno != ENOTSUP)
- + {
- + glnx_set_prefix_error_from_errno (error, "%s", "llistxattr");
- + goto out;
- + }
- + }
- + else if (bytes_read > 0)
- + {
- + xattr_names = g_malloc (bytes_read);
- + if (path)
- + real_size = llistxattr (path, xattr_names, bytes_read);
- + else
- + real_size = flistxattr (fd, xattr_names, bytes_read);
- + if (real_size < 0)
- + {
- + if (errno == ERANGE)
- + {
- + g_free (xattr_names);
- + goto again;
- + }
- + glnx_set_prefix_error_from_errno (error, "%s", "llistxattr");
- + goto out;
- + }
- + else if (real_size > 0)
- + {
- + xattr_names_canonical = canonicalize_xattrs (xattr_names, real_size);
- +
- + if (!read_xattr_name_array (path, fd, xattr_names_canonical, real_size, &builder, error))
- + goto out;
- + }
- + }
- +
- + ret_xattrs = g_variant_builder_end (&builder);
- + builder_initialized = FALSE;
- + g_variant_ref_sink (ret_xattrs);
- +
- + ret = TRUE;
- + if (out_xattrs)
- + *out_xattrs = g_steal_pointer (&ret_xattrs);
- + out:
- + if (!builder_initialized)
- + g_variant_builder_clear (&builder);
- + return ret;
- +}
- +
- +/**
- + * glnx_fd_get_all_xattrs:
- + * @fd: a file descriptor
- + * @out_xattrs: (out): A new #GVariant containing the extended attributes
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Read all extended attributes from @fd in a canonical sorted order, and
- + * set @out_xattrs with the result.
- + *
- + * If the filesystem does not support extended attributes, @out_xattrs
- + * will have 0 elements, and this function will return successfully.
- + */
- +gboolean
- +glnx_fd_get_all_xattrs (int fd,
- + GVariant **out_xattrs,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + return get_xattrs_impl (NULL, fd, out_xattrs,
- + cancellable, error);
- +}
- +
- +/**
- + * glnx_dfd_name_get_all_xattrs:
- + * @dfd: Parent directory file descriptor
- + * @name: File name
- + * @out_xattrs: (out): Extended attribute set
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Load all extended attributes for the file named @name residing in
- + * directory @dfd.
- + */
- +gboolean
- +glnx_dfd_name_get_all_xattrs (int dfd,
- + const char *name,
- + GVariant **out_xattrs,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + if (G_IN_SET(dfd, AT_FDCWD, -1))
- + {
- + return get_xattrs_impl (name, -1, out_xattrs, cancellable, error);
- + }
- + else
- + {
- + char buf[PATH_MAX];
- + /* A workaround for the lack of lgetxattrat(), thanks to Florian Weimer:
- + * https://mail.gnome.org/archives/ostree-list/2014-February/msg00017.html
- + */
- + snprintf (buf, sizeof (buf), "/proc/self/fd/%d/%s", dfd, name);
- + return get_xattrs_impl (buf, -1, out_xattrs, cancellable, error);
- + }
- +}
- +
- +static gboolean
- +set_all_xattrs_for_path (const char *path,
- + GVariant *xattrs,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + const guint n = g_variant_n_children (xattrs);
- + for (guint i = 0; i < n; i++)
- + {
- + const guint8* name;
- + g_autoptr(GVariant) value = NULL;
- + g_variant_get_child (xattrs, i, "(^&ay@ay)",
- + &name, &value);
- +
- + gsize value_len;
- + const guint8* value_data = g_variant_get_fixed_array (value, &value_len, 1);
- +
- + if (lsetxattr (path, (char*)name, (char*)value_data, value_len, 0) < 0)
- + return glnx_throw_errno_prefix (error, "lsetxattr");
- + }
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_dfd_name_set_all_xattrs:
- + * @dfd: Parent directory file descriptor
- + * @name: File name
- + * @xattrs: Extended attribute set
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * Set all extended attributes for the file named @name residing in
- + * directory @dfd.
- + */
- +gboolean
- +glnx_dfd_name_set_all_xattrs (int dfd,
- + const char *name,
- + GVariant *xattrs,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + if (G_IN_SET(dfd, AT_FDCWD, -1))
- + {
- + return set_all_xattrs_for_path (name, xattrs, cancellable, error);
- + }
- + else
- + {
- + char buf[PATH_MAX];
- + /* A workaround for the lack of lsetxattrat(), thanks to Florian Weimer:
- + * https://mail.gnome.org/archives/ostree-list/2014-February/msg00017.html
- + */
- + snprintf (buf, sizeof (buf), "/proc/self/fd/%d/%s", dfd, name);
- + return set_all_xattrs_for_path (buf, xattrs, cancellable, error);
- + }
- +}
- +
- +/**
- + * glnx_fd_set_all_xattrs:
- + * @fd: File descriptor
- + * @xattrs: Extended attributes
- + * @cancellable: Cancellable
- + * @error: Error
- + *
- + * For each attribute in @xattrs, set its value on the file or
- + * directory referred to by @fd. This function does not remove any
- + * attributes not in @xattrs.
- + */
- +gboolean
- +glnx_fd_set_all_xattrs (int fd,
- + GVariant *xattrs,
- + GCancellable *cancellable,
- + GError **error)
- +{
- + const guint n = g_variant_n_children (xattrs);
- + for (guint i = 0; i < n; i++)
- + {
- + const guint8* name;
- + g_autoptr(GVariant) value = NULL;
- + g_variant_get_child (xattrs, i, "(^&ay@ay)",
- + &name, &value);
- +
- + gsize value_len;
- + const guint8* value_data = g_variant_get_fixed_array (value, &value_len, 1);
- +
- + if (TEMP_FAILURE_RETRY (fsetxattr (fd, (char*)name, (char*)value_data, value_len, 0)) < 0)
- + return glnx_throw_errno_prefix (error, "fsetxattr");
- + }
- +
- + return TRUE;
- +}
- +
- +/**
- + * glnx_lgetxattrat:
- + * @dfd: Directory file descriptor
- + * @subpath: Subpath
- + * @attribute: Extended attribute to retrieve
- + * @error: Error
- + *
- + * Retrieve an extended attribute value, relative to a directory file
- + * descriptor.
- + */
- +GBytes *
- +glnx_lgetxattrat (int dfd,
- + const char *subpath,
- + const char *attribute,
- + GError **error)
- +{
- + char pathbuf[PATH_MAX];
- + snprintf (pathbuf, sizeof (pathbuf), "/proc/self/fd/%d/%s", dfd, subpath);
- +
- + ssize_t bytes_read, real_size;
- + if (TEMP_FAILURE_RETRY (bytes_read = lgetxattr (pathbuf, attribute, NULL, 0)) < 0)
- + return glnx_null_throw_errno_prefix (error, "lgetxattr");
- +
- + g_autofree guint8 *buf = g_malloc (bytes_read);
- + if (TEMP_FAILURE_RETRY (real_size = lgetxattr (pathbuf, attribute, buf, bytes_read)) < 0)
- + return glnx_null_throw_errno_prefix (error, "lgetxattr");
- +
- + return g_bytes_new_take (g_steal_pointer (&buf), real_size);
- +}
- +
- +/**
- + * glnx_fgetxattr_bytes:
- + * @fd: Directory file descriptor
- + * @attribute: Extended attribute to retrieve
- + * @error: Error
- + *
- + * Returns: (transfer full): An extended attribute value, or %NULL on error
- + */
- +GBytes *
- +glnx_fgetxattr_bytes (int fd,
- + const char *attribute,
- + GError **error)
- +{
- + ssize_t bytes_read, real_size;
- +
- + if (TEMP_FAILURE_RETRY (bytes_read = fgetxattr (fd, attribute, NULL, 0)) < 0)
- + return glnx_null_throw_errno_prefix (error, "fgetxattr");
- +
- + g_autofree guint8 *buf = g_malloc (bytes_read);
- + if (TEMP_FAILURE_RETRY (real_size = fgetxattr (fd, attribute, buf, bytes_read)) < 0)
- + return glnx_null_throw_errno_prefix (error, "fgetxattr");
- +
- + return g_bytes_new_take (g_steal_pointer (&buf), real_size);
- +}
- +
- +/**
- + * glnx_lsetxattrat:
- + * @dfd: Directory file descriptor
- + * @subpath: Path
- + * @attribute: An attribute name
- + * @value: (array length=len) (element-type guint8): Attribute value
- + * @len: Length of @value
- + * @flags: Flags, containing either XATTR_CREATE or XATTR_REPLACE
- + * @error: Error
- + *
- + * Set an extended attribute, relative to a directory file descriptor.
- + */
- +gboolean
- +glnx_lsetxattrat (int dfd,
- + const char *subpath,
- + const char *attribute,
- + const guint8 *value,
- + gsize len,
- + int flags,
- + GError **error)
- +{
- + char pathbuf[PATH_MAX];
- + snprintf (pathbuf, sizeof (pathbuf), "/proc/self/fd/%d/%s", dfd, subpath);
- +
- + if (TEMP_FAILURE_RETRY (lsetxattr (subpath, attribute, value, len, flags)) < 0)
- + return glnx_throw_errno_prefix (error, "lsetxattr");
- +
- + return TRUE;
- +}
- +
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/glnx-xattrs.h flatpak-builder-0.10.6/libglnx/glnx-xattrs.h
- --- flatpak-builder-0.10.6.orig/libglnx/glnx-xattrs.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/glnx-xattrs.h 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,78 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2014,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <glnx-backport-autocleanups.h>
- +#include <limits.h>
- +#include <dirent.h>
- +#include <sys/stat.h>
- +#include <fcntl.h>
- +#include <sys/xattr.h>
- +
- +G_BEGIN_DECLS
- +
- +gboolean
- +glnx_dfd_name_get_all_xattrs (int dfd,
- + const char *name,
- + GVariant **out_xattrs,
- + GCancellable *cancellable,
- + GError **error);
- +
- +gboolean
- +glnx_fd_get_all_xattrs (int fd,
- + GVariant **out_xattrs,
- + GCancellable *cancellable,
- + GError **error);
- +
- +gboolean
- +glnx_dfd_name_set_all_xattrs (int dfd,
- + const char *name,
- + GVariant *xattrs,
- + GCancellable *cancellable,
- + GError **error);
- +
- +gboolean
- +glnx_fd_set_all_xattrs (int fd,
- + GVariant *xattrs,
- + GCancellable *cancellable,
- + GError **error);
- +
- +GBytes *
- +glnx_lgetxattrat (int dfd,
- + const char *subpath,
- + const char *attribute,
- + GError **error);
- +
- +GBytes *
- +glnx_fgetxattr_bytes (int fd,
- + const char *attribute,
- + GError **error);
- +
- +gboolean
- +glnx_lsetxattrat (int dfd,
- + const char *subpath,
- + const char *attribute,
- + const guint8 *value,
- + gsize len,
- + int flags,
- + GError **error);
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/libglnx.doap flatpak-builder-0.10.6/libglnx/libglnx.doap
- --- flatpak-builder-0.10.6.orig/libglnx/libglnx.doap 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/libglnx.doap 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,31 @@
- +<?xml version="1.0" encoding="UTF-8"?>
- +<Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- + xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
- + xmlns:foaf="http://xmlns.com/foaf/0.1/"
- + xmlns:gnome="http://api.gnome.org/doap-extensions#"
- + xmlns="http://usefulinc.com/ns/doap#">
- +
- + <name>libglnx</name>
- + <shortname>libglnx</shortname>
- +
- + <shortdesc xml:lang="en">"Copylib" for system service modules using GLib with Linux</shortdesc>
- +
- + <description xml:lang="en">This module is intended for use by
- + infrastructure code using GLib that is also Linux specific, such as
- + ostree, NetworkManager, and others.
- + </description>
- +
- + <license rdf:resource="http://usefulinc.com/doap/licenses/lgpl" />
- + <mailing-list rdf:resource="mailto:desktop-devel-list@gnome.org" />
- +
- + <programming-language>C</programming-language>
- +
- + <maintainer>
- + <foaf:Person>
- + <foaf:name>Colin Walters</foaf:name>
- + <foaf:mbox rdf:resource="mailto:walters@verbum.org"/>
- + <gnome:userid>walters</gnome:userid>
- + </foaf:Person>
- + </maintainer>
- +
- +</Project>
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/libglnx.h flatpak-builder-0.10.6/libglnx/libglnx.h
- --- flatpak-builder-0.10.6.orig/libglnx/libglnx.h 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/libglnx.h 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,39 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2012,2013,2015 Colin Walters <walters@verbum.org>.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#pragma once
- +
- +#include <gio/gio.h>
- +
- +G_BEGIN_DECLS
- +
- +#include <glnx-macros.h>
- +#include <glnx-local-alloc.h>
- +#include <glnx-backport-autocleanups.h>
- +#include <glnx-backports.h>
- +#include <glnx-lockfile.h>
- +#include <glnx-errors.h>
- +#include <glnx-dirfd.h>
- +#include <glnx-shutil.h>
- +#include <glnx-xattrs.h>
- +#include <glnx-console.h>
- +#include <glnx-fdio.h>
- +
- +G_END_DECLS
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/libglnx.m4 flatpak-builder-0.10.6/libglnx/libglnx.m4
- --- flatpak-builder-0.10.6.orig/libglnx/libglnx.m4 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/libglnx.m4 2018-02-11 12:03:43.449373307 +0300
- @@ -0,0 +1,31 @@
- +AC_DEFUN([LIBGLNX_CONFIGURE],
- +[
- +AC_CHECK_DECLS([
- + renameat2,
- + ],
- + [], [], [[
- +#include <sys/types.h>
- +#include <unistd.h>
- +#include <sys/mount.h>
- +#include <fcntl.h>
- +#include <sched.h>
- +#include <linux/loop.h>
- +#include <linux/random.h>
- +]])
- +
- +AC_ARG_ENABLE(otmpfile,
- + [AS_HELP_STRING([--disable-otmpfile],
- + [Disable use of O_TMPFILE [default=no]])],,
- + [enable_otmpfile=yes])
- +AS_IF([test $enable_otmpfile = yes], [], [
- + AC_DEFINE([DISABLE_OTMPFILE], 1, [Define if we should avoid using O_TMPFILE])])
- +
- +AC_ARG_ENABLE(wrpseudo-compat,
- + [AS_HELP_STRING([--enable-wrpseudo-compat],
- + [Disable use syscall() and filesystem calls to for compatibility with wrpseudo [default=no]])],,
- + [enable_wrpseudo_compat=no])
- +AS_IF([test $enable_wrpseudo_compat = no], [], [
- + AC_DEFINE([ENABLE_WRPSEUDO_COMPAT], 1, [Define if we should be compatible with wrpseudo])])
- +
- +dnl end LIBGLNX_CONFIGURE
- +])
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/Makefile-libglnx.am flatpak-builder-0.10.6/libglnx/Makefile-libglnx.am
- --- flatpak-builder-0.10.6.orig/libglnx/Makefile-libglnx.am 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/Makefile-libglnx.am 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,73 @@
- +# Copyright (C) 2015 Colin Walters <walters@verbum.org>
- +#
- +# This library is free software; you can redistribute it and/or
- +# modify it under the terms of the GNU Lesser General Public
- +# License as published by the Free Software Foundation; either
- +# version 2 of the License, or (at your option) any later version.
- +#
- +# This library 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
- +# Lesser General Public License for more details.
- +#
- +# You should have received a copy of the GNU Lesser General Public
- +# License along with this library; if not, write to the
- +# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- +# Boston, MA 02111-1307, USA.
- +
- +EXTRA_DIST += \
- + $(libglnx_srcpath)/README.md \
- + $(libglnx_srcpath)/COPYING \
- + $(libglnx_srcpath)/libglnx.m4 \
- + $(NULL)
- +
- +libglnx_la_SOURCES = \
- + $(libglnx_srcpath)/glnx-macros.h \
- + $(libglnx_srcpath)/glnx-backport-autocleanups.h \
- + $(libglnx_srcpath)/glnx-backport-autoptr.h \
- + $(libglnx_srcpath)/glnx-backports.h \
- + $(libglnx_srcpath)/glnx-backports.c \
- + $(libglnx_srcpath)/glnx-local-alloc.h \
- + $(libglnx_srcpath)/glnx-local-alloc.c \
- + $(libglnx_srcpath)/glnx-errors.h \
- + $(libglnx_srcpath)/glnx-errors.c \
- + $(libglnx_srcpath)/glnx-console.h \
- + $(libglnx_srcpath)/glnx-console.c \
- + $(libglnx_srcpath)/glnx-dirfd.h \
- + $(libglnx_srcpath)/glnx-dirfd.c \
- + $(libglnx_srcpath)/glnx-fdio.h \
- + $(libglnx_srcpath)/glnx-fdio.c \
- + $(libglnx_srcpath)/glnx-lockfile.h \
- + $(libglnx_srcpath)/glnx-lockfile.c \
- + $(libglnx_srcpath)/glnx-missing-syscall.h \
- + $(libglnx_srcpath)/glnx-missing.h \
- + $(libglnx_srcpath)/glnx-xattrs.h \
- + $(libglnx_srcpath)/glnx-xattrs.c \
- + $(libglnx_srcpath)/glnx-shutil.h \
- + $(libglnx_srcpath)/glnx-shutil.c \
- + $(libglnx_srcpath)/libglnx.h \
- + $(NULL)
- +
- +libglnx_la_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
- +libglnx_la_LDFLAGS = -avoid-version -Bsymbolic-functions -export-symbols-regex "^glnx_" -no-undefined -export-dynamic
- +libglnx_la_LIBADD = $(libglnx_libs)
- +
- +libglnx_tests = test-libglnx-xattrs test-libglnx-fdio test-libglnx-errors test-libglnx-macros
- +TESTS += $(libglnx_tests)
- +
- +check_PROGRAMS += $(libglnx_tests)
- +test_libglnx_xattrs_SOURCES = $(libglnx_srcpath)/tests/test-libglnx-xattrs.c
- +test_libglnx_xattrs_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
- +test_libglnx_xattrs_LDADD = $(libglnx_libs) libglnx.la
- +
- +test_libglnx_fdio_SOURCES = $(libglnx_srcpath)/tests/test-libglnx-fdio.c
- +test_libglnx_fdio_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
- +test_libglnx_fdio_LDADD = $(libglnx_libs) libglnx.la
- +
- +test_libglnx_errors_SOURCES = $(libglnx_srcpath)/tests/test-libglnx-errors.c
- +test_libglnx_errors_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
- +test_libglnx_errors_LDADD = $(libglnx_libs) libglnx.la
- +
- +test_libglnx_macros_SOURCES = $(libglnx_srcpath)/tests/test-libglnx-macros.c
- +test_libglnx_macros_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
- +test_libglnx_macros_LDADD = $(libglnx_libs) libglnx.la
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/README.md flatpak-builder-0.10.6/libglnx/README.md
- --- flatpak-builder-0.10.6.orig/libglnx/README.md 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/README.md 2018-02-11 12:03:43.448373307 +0300
- @@ -0,0 +1,52 @@
- +libglnx is the successor to libgsystem: https://git.gnome.org/browse/libgsystem
- +
- +It is for modules which depend on both GLib and Linux, intended to be
- +used as a git submodule.
- +
- +Features:
- +
- + - File APIs which use `openat()` like APIs, but also take a `GCancellable`
- + to support dynamic cancellation
- + - APIs also have a `GError` parameter
- + - High level "shutil", somewhat inspired by Python's
- + - A "console" API for tty output
- + - A backport of the GLib cleanup macros for projects which can't yet take
- + a dependency on 2.40.
- +
- +Why?
- +----
- +
- +There are multiple projects which have a hard dependency on Linux and
- +GLib, such as NetworkManager, ostree, flatpak, etc. It makes sense
- +for them to be able to share Linux-specific APIs.
- +
- +This module also contains some code taken from systemd, which has very
- +high quality LGPLv2+ shared library code, but most of the internal
- +shared library is private, and not namespaced.
- +
- +One could also compare this project to gnulib; the salient differences
- +there are that at least some of this module is eventually destined for
- +inclusion in GLib.
- +
- +Porting from libgsystem
- +-----------------------
- +
- +For all of the filesystem access code, libglnx exposes only
- +fd-relative API, not `GFile*`. It does use `GCancellable` where
- +applicable.
- +
- +For local allocation macros, you should start using the `g_auto`
- +macros from GLib. A backport is included in libglnx. There are a few
- +APIs not defined in GLib yet, such as `glnx_fd_close`.
- +
- +`gs_transfer_out_value` is replaced by `g_steal_pointer`.
- +
- +Contributing
- +------------
- +
- +Currently there is not a Bugzilla product - one may be created
- +in the future. You can submit PRs against the Github mirror:
- +
- +https://github.com/GNOME/libglnx/pulls
- +
- +Or alternatively, email one of the maintainers directly.
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/tests/test-libglnx-errors.c flatpak-builder-0.10.6/libglnx/tests/test-libglnx-errors.c
- --- flatpak-builder-0.10.6.orig/libglnx/tests/test-libglnx-errors.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/tests/test-libglnx-errors.c 2018-02-11 12:03:43.450373307 +0300
- @@ -0,0 +1,183 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2017 Red Hat, Inc.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +#include "libglnx.h"
- +#include <glib.h>
- +#include <stdlib.h>
- +#include <gio/gio.h>
- +#include <string.h>
- +
- +static void
- +test_error_throw (void)
- +{
- + g_autoptr(GError) error = NULL;
- +
- + g_assert (!glnx_throw (&error, "foo: %s %d", "hello", 42));
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
- + g_assert_cmpstr (error->message, ==, "foo: hello 42");
- + g_clear_error (&error);
- +
- + gpointer dummy = glnx_null_throw (&error, "literal foo");
- + g_assert (dummy == NULL);
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
- + g_assert_cmpstr (error->message, ==, "literal foo");
- + g_clear_error (&error);
- +
- + gpointer dummy2 = glnx_null_throw (&error, "foo: %s %d", "hola", 24);
- + g_assert (dummy2 == NULL);
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
- + g_assert_cmpstr (error->message, ==, "foo: hola 24");
- + g_clear_error (&error);
- +}
- +
- +static void
- +test_error_errno (void)
- +{
- + g_autoptr(GError) error = NULL;
- + const char noent_path[] = "/enoent-this-should-not-exist";
- + int fd;
- +
- + fd = open (noent_path, O_RDONLY);
- + if (fd < 0)
- + {
- + g_assert (!glnx_throw_errno (&error));
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
- + g_assert (!glnx_prefix_error (&error, "myprefix"));
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
- + g_assert (g_str_has_prefix (error->message, "myprefix: "));
- + g_clear_error (&error);
- + }
- + else
- + g_assert_cmpint (fd, ==, -1);
- +
- + fd = open (noent_path, O_RDONLY);
- + if (fd < 0)
- + {
- + gpointer dummy = glnx_null_throw_errno (&error);
- + g_assert (dummy == NULL);
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
- + dummy = glnx_prefix_error_null (&error, "myprefix");
- + g_assert (dummy == NULL);
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
- + g_assert (g_str_has_prefix (error->message, "myprefix: "));
- + g_clear_error (&error);
- + }
- + else
- + g_assert_cmpint (fd, ==, -1);
- +
- + fd = open (noent_path, O_RDONLY);
- + if (fd < 0)
- + {
- + g_autofree char *expected_prefix = g_strdup_printf ("Failed to open %s", noent_path);
- + g_assert (!glnx_throw_errno_prefix (&error, "Failed to open %s", noent_path));
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
- + g_assert (g_str_has_prefix (error->message, expected_prefix));
- + g_clear_error (&error);
- + /* And test the legacy wrapper */
- + glnx_set_prefix_error_from_errno (&error, "Failed to open %s", noent_path);
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
- + g_assert (g_str_has_prefix (error->message, expected_prefix));
- + g_clear_error (&error);
- + }
- + else
- + g_assert_cmpint (fd, ==, -1);
- +
- + fd = open (noent_path, O_RDONLY);
- + if (fd < 0)
- + {
- + gpointer dummy = glnx_null_throw_errno_prefix (&error, "Failed to open file");
- + g_assert (dummy == NULL);
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
- + g_assert (g_str_has_prefix (error->message, "Failed to open file"));
- + g_clear_error (&error);
- + }
- + else
- + g_assert_cmpint (fd, ==, -1);
- +
- + fd = open (noent_path, O_RDONLY);
- + if (fd < 0)
- + {
- + gpointer dummy = glnx_null_throw_errno_prefix (&error, "Failed to open %s", noent_path);
- + g_assert (dummy == NULL);
- + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
- + g_assert (g_str_has_prefix (error->message, glnx_strjoina ("Failed to open ", noent_path)));
- + g_clear_error (&error);
- + }
- + else
- + g_assert_cmpint (fd, ==, -1);
- +}
- +
- +static void
- +test_error_auto_nothrow (GError **error)
- +{
- + GLNX_AUTO_PREFIX_ERROR("foo", error);
- + /* Side effect to avoid otherwise empty function */
- + g_assert_no_error (*error);
- +}
- +
- +static void
- +test_error_auto_throw (GError **error)
- +{
- + GLNX_AUTO_PREFIX_ERROR("foo", error);
- + (void) glnx_throw (error, "oops");
- +}
- +
- +static void
- +test_error_auto_throw_recurse (GError **error)
- +{
- + GLNX_AUTO_PREFIX_ERROR("foo", error);
- +
- + if (TRUE)
- + {
- + GLNX_AUTO_PREFIX_ERROR("bar", error);
- + (void) glnx_throw (error, "oops");
- + }
- +}
- +
- +static void
- +test_error_auto (void)
- +{
- + g_autoptr(GError) error = NULL;
- + test_error_auto_nothrow (&error);
- + g_assert_no_error (error);
- + test_error_auto_throw (&error);
- + g_assert_nonnull (error);
- + g_assert_cmpstr (error->message, ==, "foo: oops");
- + g_clear_error (&error);
- + test_error_auto_throw_recurse (&error);
- + g_assert_nonnull (error);
- + g_assert_cmpstr (error->message, ==, "foo: bar: oops");
- +}
- +
- +int main (int argc, char **argv)
- +{
- + int ret;
- +
- + g_test_init (&argc, &argv, NULL);
- +
- + g_test_add_func ("/error-throw", test_error_throw);
- + g_test_add_func ("/error-errno", test_error_errno);
- + g_test_add_func ("/error-auto", test_error_auto);
- +
- + ret = g_test_run();
- +
- + return ret;
- +}
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/tests/test-libglnx-fdio.c flatpak-builder-0.10.6/libglnx/tests/test-libglnx-fdio.c
- --- flatpak-builder-0.10.6.orig/libglnx/tests/test-libglnx-fdio.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/tests/test-libglnx-fdio.c 2018-02-11 12:03:43.450373307 +0300
- @@ -0,0 +1,206 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2017 Red Hat, Inc.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +#include "libglnx.h"
- +#include <glib.h>
- +#include <stdlib.h>
- +#include <gio/gio.h>
- +#include <err.h>
- +#include <string.h>
- +
- +static gboolean
- +renameat_test_setup (int *out_srcfd, int *out_destfd,
- + GError **error)
- +{
- + glnx_fd_close int srcfd = -1;
- + glnx_fd_close int destfd = -1;
- +
- + (void) glnx_shutil_rm_rf_at (AT_FDCWD, "srcdir", NULL, NULL);
- + if (mkdir ("srcdir", 0755) < 0)
- + err (1, "mkdir");
- + if (!glnx_opendirat (AT_FDCWD, "srcdir", TRUE, &srcfd, error))
- + return FALSE;
- + (void) glnx_shutil_rm_rf_at (AT_FDCWD, "destdir", NULL, NULL);
- + if (mkdir ("destdir", 0755) < 0)
- + err (1, "mkdir");
- + if (!glnx_opendirat (AT_FDCWD, "destdir", TRUE, &destfd, error))
- + return FALSE;
- +
- + if (!glnx_file_replace_contents_at (srcfd, "foo", (guint8*)"foo contents", strlen ("foo contents"),
- + GLNX_FILE_REPLACE_NODATASYNC, NULL, error))
- + return FALSE;
- + if (!glnx_file_replace_contents_at (destfd, "bar", (guint8*)"bar contents", strlen ("bar contents"),
- + GLNX_FILE_REPLACE_NODATASYNC, NULL, error))
- + return FALSE;
- +
- + *out_srcfd = srcfd; srcfd = -1;
- + *out_destfd = destfd; destfd = -1;
- + return TRUE;
- +}
- +
- +static void
- +test_renameat2_noreplace (void)
- +{
- + g_autoptr(GError) local_error = NULL;
- + GError **error = &local_error;
- + glnx_fd_close int srcfd = -1;
- + glnx_fd_close int destfd = -1;
- + struct stat stbuf;
- +
- + if (!renameat_test_setup (&srcfd, &destfd, error))
- + goto out;
- +
- + if (glnx_renameat2_noreplace (srcfd, "foo", destfd, "bar") == 0)
- + g_assert_not_reached ();
- + else
- + {
- + g_assert_cmpint (errno, ==, EEXIST);
- + }
- +
- + if (glnx_renameat2_noreplace (srcfd, "foo", destfd, "baz") < 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- + if (!glnx_fstatat (destfd, "bar", &stbuf, AT_SYMLINK_NOFOLLOW, error))
- + goto out;
- +
- + if (fstatat (srcfd, "foo", &stbuf, AT_SYMLINK_NOFOLLOW) == 0)
- + g_assert_not_reached ();
- + else
- + g_assert_cmpint (errno, ==, ENOENT);
- +
- + out:
- + g_assert_no_error (local_error);
- +}
- +
- +static void
- +test_renameat2_exchange (void)
- +{
- + g_autoptr(GError) local_error = NULL;
- + GError **error = &local_error;
- + glnx_fd_close int srcfd = -1;
- + glnx_fd_close int destfd = -1;
- + struct stat stbuf;
- +
- + if (!renameat_test_setup (&srcfd, &destfd, error))
- + goto out;
- +
- + if (glnx_renameat2_exchange (AT_FDCWD, "srcdir", AT_FDCWD, "destdir") < 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- +
- + /* Ensure the dir fds are the same */
- + if (fstatat (srcfd, "foo", &stbuf, AT_SYMLINK_NOFOLLOW) < 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- + if (fstatat (destfd, "bar", &stbuf, AT_SYMLINK_NOFOLLOW) < 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- + /* But the dirs should be swapped */
- + if (fstatat (AT_FDCWD, "destdir/foo", &stbuf, AT_SYMLINK_NOFOLLOW) < 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- + if (fstatat (AT_FDCWD, "srcdir/bar", &stbuf, AT_SYMLINK_NOFOLLOW) < 0)
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- +
- + out:
- + g_assert_no_error (local_error);
- +}
- +
- +static void
- +test_tmpfile (void)
- +{
- + g_autoptr(GError) local_error = NULL;
- + GError **error = &local_error;
- + g_auto(GLnxTmpfile) tmpf = { 0, };
- +
- + if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, ".", O_WRONLY|O_CLOEXEC, &tmpf, error))
- + goto out;
- +
- + if (glnx_loop_write (tmpf.fd, "foo", strlen ("foo")) < 0)
- + {
- + (void)glnx_throw_errno_prefix (error, "write");
- + goto out;
- + }
- +
- + if (glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_NOREPLACE, AT_FDCWD, "foo", error))
- + goto out;
- +
- + out:
- + g_assert_no_error (local_error);
- +}
- +
- +static void
- +test_stdio_file (void)
- +{
- + g_autoptr(GError) local_error = NULL;
- + GError **error = &local_error;
- + g_auto(GLnxTmpfile) tmpf = { 0, };
- + g_autoptr(FILE) f = NULL;
- +
- + if (!glnx_open_anonymous_tmpfile (O_RDWR|O_CLOEXEC, &tmpf, error))
- + goto out;
- + f = fdopen (tmpf.fd, "w");
- + if (!f)
- + {
- + (void)glnx_throw_errno_prefix (error, "fdopen");
- + goto out;
- + }
- +
- + if (fwrite ("hello", 1, strlen ("hello"), f) != strlen ("hello"))
- + {
- + (void)glnx_throw_errno_prefix (error, "fwrite");
- + goto out;
- + }
- + if (!glnx_stdio_file_flush (f, error))
- + goto out;
- +
- + out:
- + g_assert_no_error (local_error);
- +}
- +
- +int main (int argc, char **argv)
- +{
- + int ret;
- +
- + g_test_init (&argc, &argv, NULL);
- +
- + g_test_add_func ("/tmpfile", test_tmpfile);
- + g_test_add_func ("/stdio-file", test_stdio_file);
- + g_test_add_func ("/renameat2-noreplace", test_renameat2_noreplace);
- + g_test_add_func ("/renameat2-exchange", test_renameat2_exchange);
- +
- + ret = g_test_run();
- +
- + return ret;
- +}
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/tests/test-libglnx-macros.c flatpak-builder-0.10.6/libglnx/tests/test-libglnx-macros.c
- --- flatpak-builder-0.10.6.orig/libglnx/tests/test-libglnx-macros.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/tests/test-libglnx-macros.c 2018-02-11 12:03:43.450373307 +0300
- @@ -0,0 +1,109 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2017 Red Hat, Inc.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +#include "libglnx.h"
- +#include <glib.h>
- +#include <stdlib.h>
- +#include <gio/gio.h>
- +#include <string.h>
- +
- +static void
- +test_inset (void)
- +{
- + g_assert (G_IN_SET (7, 7));
- + g_assert (G_IN_SET (7, 42, 7));
- + g_assert (G_IN_SET (7, 7,42,3,9));
- + g_assert (G_IN_SET (42, 7,42,3,9));
- + g_assert (G_IN_SET (3, 7,42,3,9));
- + g_assert (G_IN_SET (9, 7,42,3,9));
- + g_assert (!G_IN_SET (8, 7,42,3,9));
- + g_assert (!G_IN_SET (-1, 7,42,3,9));
- + g_assert (G_IN_SET ('x', 'a', 'x', 'c'));
- + g_assert (!G_IN_SET ('y', 'a', 'x', 'c'));
- +}
- +
- +static void
- +test_hash_table_foreach (void)
- +{
- + /* use var names all different from the macro metavars to ensure proper
- + * substitution */
- + g_autoptr(GHashTable) table = g_hash_table_new (g_str_hash, g_str_equal);
- + const char *keys[] = {"key1", "key2"};
- + const char *vals[] = {"val1", "val2"};
- + g_hash_table_insert (table, (gpointer)keys[0], (gpointer)vals[0]);
- + g_hash_table_insert (table, (gpointer)keys[1], (gpointer)vals[1]);
- +
- + guint i = 0;
- + GLNX_HASH_TABLE_FOREACH_IT (table, it, const char*, key, const char*, val)
- + {
- + g_assert_cmpstr (key, ==, keys[i]);
- + g_assert_cmpstr (val, ==, vals[i]);
- + i++;
- + }
- + g_assert_cmpuint (i, ==, 2);
- +
- + i = 0;
- + GLNX_HASH_TABLE_FOREACH_IT (table, it, const char*, key, const char*, val)
- + {
- + g_hash_table_iter_remove (&it);
- + break;
- + }
- + g_assert_cmpuint (g_hash_table_size (table), ==, 1);
- +
- + g_hash_table_insert (table, (gpointer)keys[1], (gpointer)vals[1]);
- + g_assert_cmpuint (g_hash_table_size (table), ==, 1);
- +
- + g_hash_table_insert (table, (gpointer)keys[0], (gpointer)vals[0]);
- + g_assert_cmpuint (g_hash_table_size (table), ==, 2);
- +
- + i = 0;
- + GLNX_HASH_TABLE_FOREACH_KV (table, const char*, key, const char*, val)
- + {
- + g_assert_cmpstr (key, ==, keys[i]);
- + g_assert_cmpstr (val, ==, vals[i]);
- + i++;
- + }
- + g_assert_cmpuint (i, ==, 2);
- +
- + i = 0;
- + GLNX_HASH_TABLE_FOREACH (table, const char*, key)
- + {
- + g_assert_cmpstr (key, ==, keys[i]);
- + i++;
- + }
- + g_assert_cmpuint (i, ==, 2);
- +
- + i = 0;
- + GLNX_HASH_TABLE_FOREACH_V (table, const char*, val)
- + {
- + g_assert_cmpstr (val, ==, vals[i]);
- + i++;
- + }
- + g_assert_cmpuint (i, ==, 2);
- +}
- +
- +int main (int argc, char **argv)
- +{
- + g_test_init (&argc, &argv, NULL);
- + g_test_add_func ("/inset", test_inset);
- + g_test_add_func ("/hash_table_foreach", test_hash_table_foreach);
- + return g_test_run();
- +}
- diff -Nuar flatpak-builder-0.10.6.orig/libglnx/tests/test-libglnx-xattrs.c flatpak-builder-0.10.6/libglnx/tests/test-libglnx-xattrs.c
- --- flatpak-builder-0.10.6.orig/libglnx/tests/test-libglnx-xattrs.c 1970-01-01 02:00:00.000000000 +0200
- +++ flatpak-builder-0.10.6/libglnx/tests/test-libglnx-xattrs.c 2018-02-11 12:03:43.450373307 +0300
- @@ -0,0 +1,287 @@
- +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- + *
- + * Copyright (C) 2017 Red Hat, Inc.
- + *
- + * This library is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU Lesser General Public
- + * License as published by the Free Software Foundation; either
- + * version 2 of the License, or (at your option) any later version.
- + *
- + * This library 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
- + * Lesser General Public License for more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the
- + * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- + * Boston, MA 02111-1307, USA.
- + */
- +
- +#include "config.h"
- +#include "libglnx.h"
- +#include <glib.h>
- +#include <stdlib.h>
- +#include <gio/gio.h>
- +#include <string.h>
- +
- +#define XATTR_THREAD_RUN_TIME_USECS (5 * G_USEC_PER_SEC)
- +
- +struct XattrWorker {
- + int dfd;
- + gboolean is_writer;
- + guint n_attrs_read;
- +};
- +
- +typedef enum {
- + WRITE_RUN_MUTATE,
- + WRITE_RUN_CREATE,
- +} WriteType;
- +
- +static gboolean
- +set_random_xattr_value (int fd, const char *name, GError **error)
- +{
- + const guint8 randxattrbyte = g_random_int_range (0, 256);
- + const guint32 randxattrvalue_len = (g_random_int () % 256) + 1; /* Picked to be not too small or large */
- + g_autofree char *randxattrvalue = g_malloc (randxattrvalue_len);
- +
- + memset (randxattrvalue, randxattrbyte, randxattrvalue_len);
- +
- + if (fsetxattr (fd, name, randxattrvalue, randxattrvalue_len, 0) < 0)
- + {
- + glnx_set_error_from_errno (error);
- + return FALSE;
- + }
- +
- + return TRUE;
- +}
- +
- +static gboolean
- +add_random_xattrs (int fd, GError **error)
- +{
- + const guint nattrs = MIN (2, g_random_int () % 16);
- +
- + for (guint i = 0; i < nattrs; i++)
- + {
- + guint32 randxattrname_v = g_random_int ();
- + g_autofree char *randxattrname = g_strdup_printf ("user.test%u", randxattrname_v);
- +
- + if (!set_random_xattr_value (fd, randxattrname, error))
- + return FALSE;
- + }
- +
- + return TRUE;
- +}
- +
- +static gboolean
- +do_write_run (GLnxDirFdIterator *dfd_iter, GError **error)
- +{
- + WriteType wtype = g_random_int () % 2;
- +
- + if (wtype == WRITE_RUN_CREATE)
- + {
- + guint32 randname_v = g_random_int ();
- + g_autofree char *randname = g_strdup_printf ("file%u", randname_v);
- + glnx_fd_close int fd = -1;
- +
- + again:
- + fd = openat (dfd_iter->fd, randname, O_CREAT | O_EXCL, 0644);
- + if (fd < 0)
- + {
- + if (errno == EEXIST)
- + {
- + g_printerr ("Congratulations! I suggest purchasing a lottery ticket today!\n");
- + goto again;
- + }
- + else
- + {
- + glnx_set_error_from_errno (error);
- + return FALSE;
- + }
- + }
- +
- + if (!add_random_xattrs (fd, error))
- + return FALSE;
- + }
- + else if (wtype == WRITE_RUN_MUTATE)
- + {
- + while (TRUE)
- + {
- + struct dirent *dent;
- + if (!glnx_dirfd_iterator_next_dent (dfd_iter, &dent, NULL, error))
- + return FALSE;
- + if (!dent)
- + break;
- +
- + glnx_fd_close int fd = -1;
- + if (!glnx_openat_rdonly (dfd_iter->fd, dent->d_name, FALSE, &fd, error))
- + return FALSE;
- +
- + g_autoptr(GVariant) current_xattrs = NULL;
- + if (!glnx_fd_get_all_xattrs (fd, ¤t_xattrs, NULL, error))
- + return FALSE;
- +
- + for (int i = 0; i < g_variant_n_children (current_xattrs); i++)
- + {
- + const char *name, *value;
- + g_variant_get_child (current_xattrs, i, "(^&ay^&ay)", &name, &value);
- +
- + /* We don't want to potentially test/change xattrs like security.selinux
- + * that were injected by the system.
- + */
- + if (!g_str_has_prefix (name, "user.test"))
- + continue;
- +
- + if (!set_random_xattr_value (fd, name, error))
- + return FALSE;
- + }
- + }
- + }
- + else
- + g_assert_not_reached ();
- +
- + return TRUE;
- +}
- +
- +static gboolean
- +do_read_run (GLnxDirFdIterator *dfd_iter,
- + guint *out_n_read,
- + GError **error)
- +{
- + guint nattrs = 0;
- + while (TRUE)
- + {
- + struct dirent *dent;
- + if (!glnx_dirfd_iterator_next_dent (dfd_iter, &dent, NULL, error))
- + return FALSE;
- + if (!dent)
- + break;
- +
- + glnx_fd_close int fd = -1;
- + if (!glnx_openat_rdonly (dfd_iter->fd, dent->d_name, FALSE, &fd, error))
- + return FALSE;
- +
- + g_autoptr(GVariant) current_xattrs = NULL;
- + if (!glnx_fd_get_all_xattrs (fd, ¤t_xattrs, NULL, error))
- + return FALSE;
- +
- + /* We don't actually care about the values, just use the variable
- + * to avoid compiler warnings.
- + */
- + nattrs += g_variant_n_children (current_xattrs);
- + }
- +
- + *out_n_read = nattrs;
- + return TRUE;
- +}
- +
- +static gpointer
- +xattr_thread (gpointer data)
- +{
- + g_autoptr(GError) local_error = NULL;
- + GError **error = &local_error;
- + struct XattrWorker *worker = data;
- + guint64 end_time = g_get_monotonic_time () + XATTR_THREAD_RUN_TIME_USECS;
- + guint n_read = 0;
- +
- + while (g_get_monotonic_time () < end_time)
- + {
- + g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
- +
- + if (!glnx_dirfd_iterator_init_at (worker->dfd, ".", TRUE, &dfd_iter, error))
- + goto out;
- +
- + if (worker->is_writer)
- + {
- + if (!do_write_run (&dfd_iter, error))
- + goto out;
- + }
- + else
- + {
- + if (!do_read_run (&dfd_iter, &n_read, error))
- + goto out;
- + }
- + }
- +
- + out:
- + g_assert_no_error (local_error);
- +
- + return GINT_TO_POINTER (n_read);
- +}
- +
- +static void
- +test_xattr_races (void)
- +{
- + /* If for some reason we're built in a VM which only has one vcpu, let's still
- + * at least make the test do something.
- + */
- + /* FIXME - this deadlocks for me on 4.9.4-201.fc25.x86_64, whether
- + * using overlayfs or xfs as source/dest.
- + */
- + const guint nprocs = MAX (4, g_get_num_processors ());
- + struct XattrWorker wdata[nprocs];
- + GThread *threads[nprocs];
- + g_autoptr(GError) local_error = NULL;
- + GError **error = &local_error;
- + glnx_fd_close int dfd = -1;
- + g_autofree char *tmpdir = g_strdup_printf ("%s/libglnx-xattrs-XXXXXX",
- + getenv ("TMPDIR") ?: "/var/tmp");
- + guint nread = 0;
- +
- + if (!glnx_mkdtempat (AT_FDCWD, tmpdir, 0700, error))
- + goto out;
- +
- + if (!glnx_opendirat (AT_FDCWD, tmpdir, TRUE, &dfd, error))
- + goto out;
- +
- + /* Support people building/testing on tmpfs https://github.com/flatpak/flatpak/issues/686 */
- + if (fsetxattr (dfd, "user.test", "novalue", strlen ("novalue"), 0) < 0)
- + {
- + if (errno == EOPNOTSUPP)
- + {
- + g_test_skip ("no xattr support");
- + return;
- + }
- + else
- + {
- + glnx_set_error_from_errno (error);
- + goto out;
- + }
- + }
- +
- + for (guint i = 0; i < nprocs; i++)
- + {
- + struct XattrWorker *worker = &wdata[i];
- + worker->dfd = dfd;
- + worker->is_writer = i % 2 == 0;
- + threads[i] = g_thread_new (NULL, xattr_thread, worker);
- + }
- +
- + for (guint i = 0; i < nprocs; i++)
- + {
- + if (wdata[i].is_writer)
- + (void) g_thread_join (threads[i]);
- + else
- + nread += GPOINTER_TO_UINT (g_thread_join (threads[i]));
- + }
- +
- + g_print ("Read %u xattrs race free!\n", nread);
- +
- + (void) glnx_shutil_rm_rf_at (AT_FDCWD, tmpdir, NULL, NULL);
- +
- + out:
- + g_assert_no_error (local_error);
- +}
- +
- +int main (int argc, char **argv)
- +{
- + int ret;
- +
- + g_test_init (&argc, &argv, NULL);
- +
- + g_test_add_func ("/xattr-races", test_xattr_races);
- +
- + ret = g_test_run();
- +
- + return ret;
- +}
|